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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Return the next random u32. Read more

Return the next random u64. Read more

Fill dest with random data. Read more

Fill dest entirely with random data. Read more

Seed type, which is restricted to types mutably-dereferencable as u8 arrays (we recommend [u8; N] for some N). Read more

Create a new PRNG using the given seed. Read more

Create a new PRNG using a u64 seed. Read more

Create a new PRNG seeded from another Rng. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.