pub struct DeterministicRuntime { /* private fields */ }Expand description
Deterministic runtime providing seeded randomness and a virtual clock.
All state is fully determined by the initial seed. The virtual clock
starts at 0 and advances by a fixed increment on each read, so even the
“current time” is reproducible.
Implementations§
Source§impl DeterministicRuntime
impl DeterministicRuntime
Sourcepub fn new(seed: u64) -> Self
pub fn new(seed: u64) -> Self
Create a new deterministic runtime with the given seed.
The virtual clock starts at 0 and advances by 1 ms per call to
current_time_ms().
Sourcepub fn with_clock_increment(seed: u64, clock_increment_ns: u64) -> Self
pub fn with_clock_increment(seed: u64, clock_increment_ns: u64) -> Self
Create with a custom clock increment (in nanoseconds).
Sourcepub fn next_random_f64(&mut self) -> f64
pub fn next_random_f64(&mut self) -> f64
Generate the next random f64 in [0.0, 1.0).
Sourcepub fn next_random_range(&mut self, min: f64, max: f64) -> f64
pub fn next_random_range(&mut self, min: f64, max: f64) -> f64
Generate the next random f64 in [min, max).
Sourcepub fn current_time_ms(&mut self) -> f64
pub fn current_time_ms(&mut self) -> f64
Return the current virtual time in milliseconds, then advance the clock by the configured increment.
This mirrors the semantics of time.millis() — each call returns a
monotonically increasing value.
Sourcepub fn advance_clock(&mut self, ns: u64)
pub fn advance_clock(&mut self, ns: u64)
Manually advance the virtual clock by ns nanoseconds.