Struct urandom::rng::MockRng

source ·
pub struct MockRng<I>(pub I);
Expand description

Random number generator mock.

Produces randomness directly from the given iterator and panics when it runs out of items.

Tuple Fields

0: I

Implementations

Produces the values from the input slice as the underlying random number generator.

use urandom::rng::MockRng;

let mut rng = MockRng::slice(&[1, 2, 13, 42]);

assert_eq!(rng.next_u64(), 1);
assert_eq!(rng.next_u64(), 2);
assert_eq!(rng.next_u64(), 13);
assert_eq!(rng.next_u64(), 42);

// Any further calls to the MockRng will panic unless the underlying iterator is unbounded.

Produces the same random number repeatedly as the underlying random number generator.

use urandom::rng::MockRng;

let mut rng = MockRng::repeat(42);

assert_eq!(rng.next_u64(), 42);
assert_eq!(rng.next_u64(), 42);
assert_eq!(rng.next_u64(), 42);

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
Returns the next u32 in the sequence.
Returns the next u64 in the sequence.
Fills the next u32 elements in the sequence. Read more
Fills the next u64 elements in the sequence.
Fills the byte slice with uniform random bytes. Read more
Advances the internal state significantly. Read more
Returns a uniform random f32 in the half-open interval [1.0, 2.0). Read more
Returns a uniform random f64 in the half-open interval [1.0, 2.0). 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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
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.