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
sourceimpl RngCore for ThreadRng
impl RngCore for ThreadRng
sourcefn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
dest
with random data. Read moresourcefn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error>
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error>
dest
entirely with random data. Read moreimpl CryptoRng for ThreadRng
Auto Trait Implementations
impl !RefUnwindSafe for ThreadRng
impl !Send for ThreadRng
impl !Sync for ThreadRng
impl Unpin for ThreadRng
impl !UnwindSafe for ThreadRng
Blanket Implementations
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstablefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> CryptoRngCore for Twhere
T: CryptoRng + RngCore,
impl<T> CryptoRngCore for Twhere
T: CryptoRng + RngCore,
sourcefn as_rngcore(&mut self) -> &mut dyn RngCore
fn as_rngcore(&mut self) -> &mut dyn RngCore
RngCore
trait object.