Files
heuropt/src/core/rng.rs
T
swaits f6f41eda35 feat(core): add data types and Rng alias
Plain-data structs and the seeded Rng alias from spec §7. Each lives in
its own file under src/core/ with unit tests:

- Direction, Objective, ObjectiveSpace (with as_minimization negating
  only Maximize axes)
- Evaluation (is_feasible == constraint_violation <= 0.0)
- Candidate<D>, Population<D> (concrete, public fields, From<Vec<...>>)
- OptimizationResult<D>
- type Rng = rand::rngs::StdRng + rng_from_seed, so no public trait is
  generic over the RNG (spec §2.5)

All public types behind #[cfg_attr(feature = "serde", derive(...))] so
the optional feature wires up without changing the default surface.
2026-05-04 19:18:01 -06:00

39 lines
961 B
Rust

//! Single seeded RNG type used throughout the crate.
use rand::SeedableRng;
/// The standard RNG used by `Initializer`, `Variation`, and built-in optimizers.
///
/// Fixed to a single concrete type so the public traits never need to be
/// generic over the RNG.
pub type Rng = rand::rngs::StdRng;
/// Build a deterministic [`Rng`] from a 64-bit seed.
pub fn rng_from_seed(seed: u64) -> Rng {
Rng::seed_from_u64(seed)
}
#[cfg(test)]
mod tests {
use super::*;
use rand::Rng as _;
#[test]
fn same_seed_same_sequence() {
let mut a = rng_from_seed(42);
let mut b = rng_from_seed(42);
let av: u64 = a.random();
let bv: u64 = b.random();
assert_eq!(av, bv);
}
#[test]
fn different_seed_different_sequence() {
let mut a = rng_from_seed(1);
let mut b = rng_from_seed(2);
let av: u64 = a.random();
let bv: u64 = b.random();
assert_ne!(av, bv);
}
}