pub struct SeedStream { /* private fields */ }Expand description
A deterministic, fan-out seed generator for benchmark and training trials.
SeedStream derives independent 64-bit seeds for each (environment index,
trial index) pair, and further splits each trial seed into separate env and
agent seeds. Every derivation is a pure function of base and the index
arguments, so the same SeedStream always produces the same sequence.
§Design
Derivation uses splitmix64 — a bijective mixing function — XOR’d with
index-dependent multipliers. The env and agent branches are separated by
distinct domain constants so env_seed(t) != agent_seed(t) for all t.
§Thread safety
SeedStream holds no mutable state and is Copy. All methods are
const fn. It is safe to share across threads without synchronisation.
Implementations§
Source§impl SeedStream
impl SeedStream
Sourcepub const fn new(base: u64) -> Self
pub const fn new(base: u64) -> Self
Creates a new SeedStream from the given base seed.
All seeds derived from this stream are fully determined by base.
Two streams constructed with the same base produce identical output.
§Examples
use rlevo_core::util::seed::SeedStream;
let stream = SeedStream::new(0xDEAD_BEEF);
assert_eq!(stream.base(), 0xDEAD_BEEF);Sourcepub const fn base(&self) -> u64
pub const fn base(&self) -> u64
Returns the base seed this stream was constructed with.
Useful for serialising or logging the root of a reproducible run.
§Examples
use rlevo_core::util::seed::SeedStream;
let stream = SeedStream::new(42);
assert_eq!(stream.base(), 42);Sourcepub const fn trial_seed(&self, env_idx: usize, trial_idx: usize) -> u64
pub const fn trial_seed(&self, env_idx: usize, trial_idx: usize) -> u64
Derives a deterministic seed for a specific (env index, trial index) pair.
The returned value is the root from which env_seed
and agent_seed are derived for that trial.
Different (env_idx, trial_idx) pairs always produce different seeds.
§Examples
use rlevo_core::util::seed::SeedStream;
let stream = SeedStream::new(42);
// Repeated calls with identical arguments are stable.
assert_eq!(stream.trial_seed(0, 0), stream.trial_seed(0, 0));
// Different index pairs yield different seeds.
assert_ne!(stream.trial_seed(0, 0), stream.trial_seed(0, 1));
assert_ne!(stream.trial_seed(0, 0), stream.trial_seed(1, 0));Sourcepub const fn env_seed(&self, trial_seed: u64) -> u64
pub const fn env_seed(&self, trial_seed: u64) -> u64
Derives the environment seed for a given trial seed.
Pass the result of trial_seed as trial_seed.
The returned value is guaranteed to differ from agent_seed
for the same input, preventing env and agent RNGs from correlating.
§Examples
use rlevo_core::util::seed::SeedStream;
let stream = SeedStream::new(42);
let t = stream.trial_seed(0, 0);
let env_seed = stream.env_seed(t);
let agent_seed = stream.agent_seed(t);
assert_ne!(env_seed, agent_seed);Sourcepub const fn agent_seed(&self, trial_seed: u64) -> u64
pub const fn agent_seed(&self, trial_seed: u64) -> u64
Derives the agent seed for a given trial seed.
Pass the result of trial_seed as trial_seed.
The returned value is guaranteed to differ from env_seed
for the same input, preventing agent and env RNGs from correlating.
§Examples
use rlevo_core::util::seed::SeedStream;
let stream = SeedStream::new(42);
let t = stream.trial_seed(0, 0);
// agent_seed and env_seed are derived with different domain constants,
// so they are always distinct for the same trial seed.
assert_ne!(stream.agent_seed(t), stream.env_seed(t));
// Repeated calls are stable.
assert_eq!(stream.agent_seed(t), stream.agent_seed(t));Trait Implementations§
Source§impl Clone for SeedStream
impl Clone for SeedStream
Source§fn clone(&self) -> SeedStream
fn clone(&self) -> SeedStream
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for SeedStream
Auto Trait Implementations§
impl Freeze for SeedStream
impl RefUnwindSafe for SeedStream
impl Send for SeedStream
impl Sync for SeedStream
impl Unpin for SeedStream
impl UnsafeUnpin for SeedStream
impl UnwindSafe for SeedStream
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<C> CloneExpand for Cwhere
C: Clone,
impl<C> CloneExpand for Cwhere
C: Clone,
fn __expand_clone_method(&self, _scope: &mut Scope) -> C
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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