pub struct ReadRng<R> { /* fields omitted */ }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.
This can be used with /dev/urandom on Unix but it is recommended to use
OsRng instead.
ReadRng uses std::io::read_exact, which retries on interrupts. All other
errors from the underlying reader, including when it does not have enough
data, will only be reported through try_fill_bytes. The other
RngCore methods will panic in case of an error.
use rand::{read, Rng};
let data = vec![1, 2, 3, 4, 5, 6, 7, 8];
let mut rng = read::ReadRng::new(&data[..]);
println!("{:x}", rng.gen::<u32>());
Create a new ReadRng from a Read.
Formats the value using the given formatter. Read more
Fill dest entirely with random data. Read more
Return a random value supporting the [Standard] distribution. Read more
Generate a random value in the range [low, high), i.e. inclusive of low and exclusive of high. Read more
Sample a new value, using the given distribution. Read more
Important traits for DistIter<'a, D, R, T>
impl<'a, D, R, T> Iterator for DistIter<'a, D, R, T> where
D: Distribution<T>,
R: Rng + 'a, type Item = T;
Create an iterator that generates values using the given distribution. Read more
Fill dest entirely with random bytes (uniform value distribution), where dest is any type supporting [AsByteSliceMut], namely slices and arrays over primitive integer types (i8, i16, u32, etc.). Read more
Fill dest entirely with random bytes (uniform value distribution), where dest is any type supporting [AsByteSliceMut], namely slices and arrays over primitive integer types (i8, i16, u32, etc.). Read more
Return a bool with a probability p of being true. Read more
Return a random element from values. Read more
Return a mutable pointer to a random element from values. Read more
Deprecated since 0.5.0
: use Rng::sample_iter(&Standard) instead
Return an iterator that will yield an infinite number of randomly generated items. Read more
Deprecated since 0.5.0
: use gen_bool instead
Return a bool with a 1 in n chance of true Read more
Deprecated since 0.5.0
: use sample_iter(&Alphanumeric) instead
Return an iterator of random characters from the set A-Z,a-z,0-9. Read more
type Error = !
🔬 This is a nightly-only experimental API. (try_from)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id)
this method will likely be replaced by an associated static
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (try_from)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from)
Mutably borrows from an owned value. Read more