Struct rand::rngs::ThreadRng

source ·
pub struct ThreadRng { /* private fields */ }
Available on crate features std and std_rng only.
Expand description

A reference to the thread-local generator

This type is a reference to a lazily-initialized thread-local generator. An instance can be obtained via thread_rng or via ThreadRng::default(). This handle is safe to use everywhere (including thread-local destructors), though it is recommended not to use inside a fork handler. The handle cannot be passed between threads (is not Send or Sync).

ThreadRng uses the same CSPRNG as StdRng, ChaCha12. As with StdRng, the algorithm may be changed, subject to reasonable expectations of security and performance.

ThreadRng is automatically seeded from OsRng with periodic reseeding (every 64 kiB, as well as “soon” after a fork on Unix — see ReseedingRng documentation for details).

Security must be considered relative to a threat model and validation requirements. ThreadRng attempts to meet basic security considerations for producing unpredictable random numbers: use a CSPRNG, use a recommended platform-specific seed (OsRng), and avoid leaking internal secrets e.g. via Debug implementation or serialization. Memory is not zeroized on drop.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Debug implementation does not leak internal state

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Return the next random u32. Read more
Return the next random u64. Read more
Fill dest with random data. Read more
Fill dest entirely with random data. Read more
Convert an RngCore to a RngReadAdapter.

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
Upcast to an RngCore trait object.

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.