Struct urandom::rng::ReadRng

source ·
pub struct ReadRng<R>(pub R);
Expand description

An RNG that reads random bytes straight from any type supporting std::io::Read, for example files.

This will work best with an infinite reader, but that is not required.

Panics

ReadRng uses std::io::Read::read_exact, which retries on interrupts. All other errors from the underlying reader, including when it does not have enough data, will panic in case of an error.

Examples

let data = [1, 2, 3, 4, 5, 6, 7, 8];
let mut rng = urandom::rng::ReadRng::new(&data[..]);

println!("{:x}", rng.next::<u32>());

Tuple Fields

0: R

Implementations

Creates a new ReadRng from a Read.

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.