pub struct RandomNumberGenerator { /* private fields */ }
Expand description
Random number generator
Main type that is capable of generating random numbers.
Implementations§
Source§impl RandomNumberGenerator
impl RandomNumberGenerator
Sourcepub fn open(id: RandomAlgorithmId) -> Result<RandomNumberGenerator>
pub fn open(id: RandomAlgorithmId) -> Result<RandomNumberGenerator>
Open a random number generator using the provided algorithm.
§Examples
let rng = RandomNumberGenerator::open(RandomAlgorithmId::Rng);
assert!(rng.is_ok());
Sourcepub fn system_preferred() -> RandomNumberGenerator
pub fn system_preferred() -> RandomNumberGenerator
Open a random number generator using the system preferred algorithm.
Windows Vista: This is not supported.
Sourcepub fn gen_random(&self, buffer: &mut [u8]) -> Result<()>
pub fn gen_random(&self, buffer: &mut [u8]) -> Result<()>
Fills a buffer with random bytes.
Use a random number for the entropy.
§Examples
let mut buffer = [0u8; 32];
let rng = RandomNumberGenerator::system_preferred();
rng.gen_random(&mut buffer).unwrap();
assert_ne!(&buffer, &[0u8; 32]);
Sourcepub fn gen_random_with_entropy_in_buffer(&self, buffer: &mut [u8]) -> Result<()>
pub fn gen_random_with_entropy_in_buffer(&self, buffer: &mut [u8]) -> Result<()>
Fills a buffer with random bytes.
This function will use the number in the buffer as additional entropy for the random number.
Windows 8 and later: This does the exact same thing as
gen_random
.
§Examples
let mut buffer = [0u8; 32];
let rng = RandomNumberGenerator::system_preferred();
rng.gen_random_with_entropy_in_buffer(&mut buffer).unwrap();
assert_ne!(&buffer, &[0u8; 32]);
Auto Trait Implementations§
impl Freeze for RandomNumberGenerator
impl RefUnwindSafe for RandomNumberGenerator
impl Send for RandomNumberGenerator
impl !Sync for RandomNumberGenerator
impl Unpin for RandomNumberGenerator
impl UnwindSafe for RandomNumberGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more