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.
Auto Trait Implementations§
impl Freeze for DeterministicRuntime
impl RefUnwindSafe for DeterministicRuntime
impl Send for DeterministicRuntime
impl Sync for DeterministicRuntime
impl Unpin for DeterministicRuntime
impl UnsafeUnpin for DeterministicRuntime
impl UnwindSafe for DeterministicRuntime
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more