pub struct DeterministicRng { /* private fields */ }Expand description
A deterministic random number generator.
TigerStyle:
- Same seed always produces same sequence
- Fork creates independent streams
- All randomness flows through this
Implementations§
Source§impl DeterministicRng
impl DeterministicRng
Sourcepub fn new(seed: u64) -> Self
pub fn new(seed: u64) -> Self
Create a new RNG with the given seed.
§Example
use umi_memory::dst::DeterministicRng;
let mut rng = DeterministicRng::new(42);
let value = rng.next_float();Sourcepub fn next_float(&mut self) -> f64
pub fn next_float(&mut self) -> f64
Generate a random float in [0, 1).
Sourcepub fn next_usize(&mut self, min: usize, max: usize) -> usize
pub fn next_usize(&mut self, min: usize, max: usize) -> usize
Sourcepub fn next_bool(&mut self, probability: f64) -> bool
pub fn next_bool(&mut self, probability: f64) -> bool
Generate a random boolean with the given probability of true.
§Panics
Panics if probability is not in [0, 1].
Sourcepub fn fork(&mut self) -> Self
pub fn fork(&mut self) -> Self
Create an independent fork of this RNG.
TigerStyle: Forks have independent sequences derived from parent.
§Example
use umi_memory::dst::DeterministicRng;
let mut rng = DeterministicRng::new(42);
let mut fork1 = rng.fork();
let mut fork2 = rng.fork();
// fork1 and fork2 have independent sequencesTrait Implementations§
Source§impl Clone for DeterministicRng
impl Clone for DeterministicRng
Auto Trait Implementations§
impl Freeze for DeterministicRng
impl RefUnwindSafe for DeterministicRng
impl Send for DeterministicRng
impl Sync for DeterministicRng
impl Unpin for DeterministicRng
impl UnwindSafe for DeterministicRng
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