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 state_bytes(&self) -> Result<Vec<u8>, FerrayError> { ... }
fn set_state_bytes(&mut self, bytes: &[u8]) -> Result<(), FerrayError> { ... }
fn next_u64_bounded(&mut self, bound: u64) -> u64 { ... }
}Expand description
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 state_bytes(&self) -> Result<Vec<u8>, FerrayError>
fn state_bytes(&self) -> Result<Vec<u8>, FerrayError>
Serialize the full internal state of this generator to a
little-endian byte vector. Pair with [set_state_bytes] to
restore.
Default impl returns an error — concrete generators that
support serialization override both methods. Used to checkpoint
reproducible experiments (#453), the rough Rust equivalent of
numpy’s Generator.bit_generator.state / __getstate__ /
__setstate__.
§Errors
FerrayError::InvalidValue if the generator does not implement
state serialization.
Sourcefn set_state_bytes(&mut self, bytes: &[u8]) -> Result<(), FerrayError>
fn set_state_bytes(&mut self, bytes: &[u8]) -> Result<(), FerrayError>
Restore the generator’s state from previously-serialized bytes
produced by [state_bytes].
§Errors
FerrayError::InvalidValue if the byte length doesn’t match
the expected state size, or if the embedded state is invalid
(e.g. all-zero state for Xoshiro256**).
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.