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
impl 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more