Index wasi args_get args_sizes_get clock_res_get clock_time_get environ_get environ_sizes_get fd_advise fd_allocate fd_close fd_datasync fd_fdstat_get fd_fdstat_set_flags fd_fdstat_set_rights fd_filestat_get fd_filestat_set_size fd_filestat_set_times fd_pread fd_prestat_dir_name fd_prestat_get fd_pwrite fd_read fd_readdir fd_renumber fd_seek fd_sync fd_tell fd_write file_stat_flags filestat iovec lookup_flags path_create_directory path_filestat_get path_filestat_set_times path_link path_open path_readlink path_remove_directory path_rename path_symlink path_unlink_file poll_oneoff proc_exit proc_raise random_get sched_yield sock_accept sock_recv sock_send sock_shutdown
Fill a buffer with high-quality random data. This function may be slow and block.
random_get (
buf: i32A pointer to the buffer where the random bytes will be writtenbuf_len: i32The number of bytes to be written
) =>
error: i32 

The random_get() function is used to fill a buffer with high-quality random data. It takes a pointer to a buffer and the number of bytes to be written as input. The function will generate random bytes and write them to the specified buffer.

Generating high-quality random data may be a slow operation and may block in certain cases, especially when the system's entropy pool is depleted. Therefore, this function should be used with caution in performance-sensitive scenarios.

Note

  • The random_get() function fills a buffer with high-quality random data.
  • It uses the getrandom crate to generate the random data.
  • The function creates a u8 buffer with the specified length and calls getrandom::getrandom() to generate random bytes.
  • If the random data is generated successfully, it writes the data to the buffer specified by buf.
  • The function returns Errno::Success if the operation is successful.
  • If there is an error generating the random data, such as when the system's entropy pool is depleted, it returns Errno::Io.

Read More