pub trait BitGenerator: Send {
// Required methods
fn next_u64(&mut self) -> u64;
fn seed_from_u64(seed: u64) -> Self
where Self: Sized;
fn jump(&mut self) -> Option<()>;
fn stream(seed: u64, stream_id: u64) -> Option<Self>
where Self: Sized;
// Provided methods
fn next_f64(&mut self) -> f64 { ... }
fn next_f32(&mut self) -> f32 { ... }
fn fill_bytes(&mut self, dest: &mut [u8]) { ... }
fn next_u64_bounded(&mut self, bound: u64) -> u64 { ... }
}Expand description
Trait for pluggable pseudo-random number generators.
All BitGenerators are Send (can be transferred between threads) but NOT Sync
(they are stateful and require &mut self).
Concrete implementations: Pcg64, Philox, Xoshiro256StarStar.
Required Methods§
Sourcefn seed_from_u64(seed: u64) -> Selfwhere
Self: Sized,
fn seed_from_u64(seed: u64) -> Selfwhere
Self: Sized,
Create a new generator seeded from a single u64.
Provided Methods§
Sourcefn next_f64(&mut self) -> f64
fn next_f64(&mut self) -> f64
Generate a uniformly distributed f64 in [0, 1).
Uses the upper 53 bits of next_u64() for full double precision.
Sourcefn fill_bytes(&mut self, dest: &mut [u8])
fn fill_bytes(&mut self, dest: &mut [u8])
Fill a byte slice with random bytes.
Sourcefn next_u64_bounded(&mut self, bound: u64) -> u64
fn next_u64_bounded(&mut self, bound: u64) -> u64
Generate a u64 in the range [0, bound) using rejection sampling.