rand::rngs::adapter

Struct ReadRng

Source
pub struct ReadRng<R> { /* private fields */ }
๐Ÿ‘ŽDeprecated since 0.8.4: removal due to lack of usage
Available on crate feature std only.
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.

This can be used with /dev/urandom on Unix but it is recommended to use OsRng instead.

ยง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 only be reported through try_fill_bytes. The other RngCore methods will panic in case of an error.

Implementationsยง

Sourceยง

impl<R: Read> ReadRng<R>

Source

pub fn new(r: R) -> ReadRng<R>

Create a new ReadRng from a Read.

Trait Implementationsยง

Sourceยง

impl<R: Debug> Debug for ReadRng<R>

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl<R: Read> RngCore for ReadRng<R>

Sourceยง

fn next_u32(&mut self) -> u32

Return the next random u32. Read more
Sourceยง

fn next_u64(&mut self) -> u64

Return the next random u64. Read more
Sourceยง

fn fill_bytes(&mut self, dest: &mut [u8])

Fill dest with random data. Read more
Sourceยง

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error>

Fill dest entirely with random data. Read more

Auto Trait Implementationsยง

ยง

impl<R> Freeze for ReadRng<R>
where R: Freeze,

ยง

impl<R> RefUnwindSafe for ReadRng<R>
where R: RefUnwindSafe,

ยง

impl<R> Send for ReadRng<R>
where R: Send,

ยง

impl<R> Sync for ReadRng<R>
where R: Sync,

ยง

impl<R> Unpin for ReadRng<R>
where R: Unpin,

ยง

impl<R> UnwindSafe for ReadRng<R>
where R: UnwindSafe,

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

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

Sourceยง

impl<R> Rng for R
where R: RngCore + ?Sized,

Sourceยง

fn gen<T>(&mut self) -> T

Return a random value supporting the Standard distribution. Read more
Sourceยง

fn gen_range<T, R>(&mut self, range: R) -> T
where T: SampleUniform, R: SampleRange<T>,

Generate a random value in the given range. Read more
Sourceยง

fn sample<T, D: Distribution<T>>(&mut self, distr: D) -> T

Sample a new value, using the given distribution. Read more
Sourceยง

fn sample_iter<T, D>(self, distr: D) -> DistIter<D, Self, T> โ“˜
where D: Distribution<T>, Self: Sized,

Create an iterator that generates values using the given distribution. Read more
Sourceยง

fn fill<T: Fill + ?Sized>(&mut self, dest: &mut T)

Fill any type implementing Fill with random data Read more
Sourceยง

fn try_fill<T: Fill + ?Sized>(&mut self, dest: &mut T) -> Result<(), Error>

Fill any type implementing Fill with random data Read more
Sourceยง

fn gen_bool(&mut self, p: f64) -> bool

Return a bool with a probability p of being true. Read more
Sourceยง

fn gen_ratio(&mut self, numerator: u32, denominator: u32) -> bool

Return a bool with a probability of numerator/denominator of being true. I.e. gen_ratio(2, 3) has chance of 2 in 3, or about 67%, of returning true. If numerator == denominator, then the returned value is guaranteed to be true. If numerator == 0, then the returned value is guaranteed to be false. Read more
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Sourceยง

fn vzip(self) -> V