Struct rand_wyrand::WyRand
source · [−]pub struct WyRand { /* private fields */ }
Expand description
An instance of the WyRand random number generator.
While not cryptographically secure, WyRand is solid enough to pass the BigCrush and practrand tests, while being extremely fast, making it ideal for non-secure uses.
Examples
Generate random number from 1 to 100
use rand::{Rng, SeedableRng};
use rand_wyrand::WyRand;
let mut wyrand = WyRand::from_entropy();
let mut bytes = [0_u8; 64];
wyrand.fill(&mut bytes);
println!("Random bytes: {bytes:?}");
Generate random bytes
use rand::{Rng, SeedableRng};
use rand_wyrand::WyRand;
let mut wyrand = WyRand::from_entropy();
println!("Random number from 1 to 100: {}", wyrand.gen_range(1..=100));
Generate random string
use rand::{distributions::Alphanumeric, Rng, SeedableRng};
use rand_wyrand::WyRand;
let mut wyrand = WyRand::from_entropy();
let rand_string: String = wyrand
.sample_iter(&Alphanumeric)
.take(16)
.map(char::from)
.collect();
println!("Random string: {rand_string}")
Trait Implementations
sourceimpl RngCore for WyRand
impl RngCore for WyRand
sourcefn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
Fill dest
with random data. Read more
sourceimpl SeedableRng for WyRand
impl SeedableRng for WyRand
impl Eq for WyRand
impl StructuralEq for WyRand
impl StructuralPartialEq for WyRand
Auto Trait Implementations
impl RefUnwindSafe for WyRand
impl Send for WyRand
impl Sync for WyRand
impl Unpin for WyRand
impl UnwindSafe for WyRand
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more