# ReadRng in rand::rngs::adapter - Rust
An RNG that reads random bytes straight from any type supporting [`std::io::Read`], for example files.
Keywords: rust, rustlang, rust-lang, ReadRng

# Struct rand::rngs::adapter::ReadRng

source · [−]

    pub struct ReadRng<R> { /* private fields */ }

👎 Deprecated since 0.8.4:

removal due to lack of usage

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> 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,

const: unstable · source

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more

source

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

const: unstable · source

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

Mutably borrows from an owned value. Read more

source

### impl<T> From<T> for T

const: unstable · source

#### fn from(t: T) -> T

Returns the argument unchanged.

source

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

const: unstable · 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<T, U> TryFrom<U> for T where
U: Into<T>,

#### type Error = Infallible

The type returned in the event of a conversion error.

const: unstable · 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>,

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

The type returned in the event of a conversion error.

const: unstable · 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