pub struct ThreadLocalRng;Expand description
A thread-local random number generator that can be used without synchronization.
This is useful for parallel processing where each thread needs its own RNG.
It uses the built-in ThreadRng from the rand crate, which is automatically
seeded from the system entropy and is thread-local.
Implementations§
Source§impl ThreadLocalRng
impl ThreadLocalRng
Sourcepub fn gen_range<T, R>(range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
pub fn gen_range<T, R>(range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Sourcepub fn get_fresh_rng()
pub fn get_fresh_rng()
Gets a new instance of the thread-local RNG.
This effectively reseeds the RNG by getting a fresh instance from the system. This is useful after a fork to ensure that child processes have different random sequences.
§Note
The built-in ThreadRng doesn’t have a direct reseed method, but getting a new
instance via thread_rng() ensures we get a properly seeded RNG.
Auto Trait Implementations§
impl Freeze for ThreadLocalRng
impl RefUnwindSafe for ThreadLocalRng
impl Send for ThreadLocalRng
impl Sync for ThreadLocalRng
impl Unpin for ThreadLocalRng
impl UnwindSafe for ThreadLocalRng
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more