pub struct ThreadRng { /* private fields */ }
Expand description
A reference to the 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 PRNG as StdRng
for security and performance
and is automatically seeded from OsRng
.
Unlike StdRng
, ThreadRng
uses the ReseedingRng
wrapper to reseed
the PRNG from fresh entropy every 64 kiB of random data as well as after a
fork on Unix (though not quite immediately; see documentation of
ReseedingRng
).
Note that the reseeding is done as an extra precaution against side-channel
attacks and mis-use (e.g. if somehow weak entropy were supplied initially).
The PRNG algorithms used are assumed to be secure.
Trait Implementations§
source§impl RngCore for ThreadRng
impl RngCore for ThreadRng
source§fn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
dest
with random data. Read more