pub trait Rng: Send {
// Required methods
fn next_u64(&mut self) -> u64;
fn fork(&mut self) -> Self
where Self: Sized;
// Provided methods
fn next_u32(&mut self) -> u32 { ... }
fn next_bool(&mut self) -> bool { ... }
fn next_fixed(&mut self) -> FixedQ32 { ... }
fn next_u64_bounded(&mut self, bound: u64) -> u64 { ... }
fn choose<'a, T>(&mut self, slice: &'a [T]) -> Option<&'a T> { ... }
fn duration_between(&mut self, min: Duration, max: Duration) -> Duration { ... }
}Expand description
Trait for random number generation in protocol execution.
Implementations can provide deterministic seeded values for reproducible testing or host entropy in runtime contexts.
§Determinism
For simulation reproducibility, always use seeded implementations like
SeededRng. The trait methods are designed to produce identical sequences
given identical seeds.
Required Methods§
Provided Methods§
Sourcefn next_fixed(&mut self) -> FixedQ32
fn next_fixed(&mut self) -> FixedQ32
Generate a random FixedQ32 value in [0, 1).
Uses the upper 32 bits as the fractional part, giving uniform distribution over the representable range.
Sourcefn next_u64_bounded(&mut self, bound: u64) -> u64
fn next_u64_bounded(&mut self, bound: u64) -> u64
Generate a random u64 in the range [0, bound).
Uses rejection sampling for uniform distribution.
Sourcefn choose<'a, T>(&mut self, slice: &'a [T]) -> Option<&'a T>
fn choose<'a, T>(&mut self, slice: &'a [T]) -> Option<&'a T>
Choose a random element from a slice.
Sourcefn duration_between(&mut self, min: Duration, max: Duration) -> Duration
fn duration_between(&mut self, min: Duration, max: Duration) -> Duration
Generate a random duration between min and max.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.