Skip to main content

fill_bytes

Function fill_bytes 

Source
pub fn fill_bytes(buffer: &mut [u8], rng: impl Fn() -> Option<u64>)
Expand description

Fills u8 buffer with random bytes generated by the provided function.

This function splits the buffer into chunks of up to 8 bytes and fills each chunk with bytes derived from a u64 value generated by rng function argument.

§Parameters

  • buffer: A mutable reference to a slice of bytes (&mut [u8]) that will be filled with random data.
  • rng: A function (Fn() -> Option<u64>) that generates random u64 values.

§Example

let mut data = [0u8; 16];
rdseed::fill_bytes(&mut data, rdseed::get64);

println!("{:?}", data); // Randomized output

§Safety Notes

  • The randomness depends on the quality of the provided rng function.
  • This function uses blocking function for extracting random data from rng function. It will panic if hardware do not supports random generator operations.