pub struct SharedRng(/* private fields */);Expand description
A wrapper around Arc<Mutex<StdRng>> that provides convenient methods
for random number generation without requiring explicit locking.
Implementations§
Sourcepub fn lock(&self) -> MutexGuard<'_, StdRng>
pub fn lock(&self) -> MutexGuard<'_, StdRng>
Lock the inner RNG for direct access. Use this when you need multiple random operations without re-locking between each one.
Sourcepub fn random_range<T, R>(&self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
pub fn random_range<T, R>(&self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Generate a random value in the given range.
Sourcepub fn random_bool(&self, p: f64) -> bool
pub fn random_bool(&self, p: f64) -> bool
Generate a random boolean with the given probability of being true.
Sourcepub fn random<T>(&self) -> Twhere
StandardUniform: Distribution<T>,
pub fn random<T>(&self) -> Twhere
StandardUniform: Distribution<T>,
Generate a random value of the given type.
Sourcepub fn random_ratio(&self, numerator: u32, denominator: u32) -> bool
pub fn random_ratio(&self, numerator: u32, denominator: u32) -> bool
Generate a random ratio - true with probability numerator/denominator.
Trait Implementations§
Auto Trait Implementations§
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