drand48 0.2.0

drand48 - POSIX.1 standard LCG random number generator
Documentation
/*
DRAND48 Linear congruential generator
implementation by Radim Kolar <hsn@sendmail.cz> 2025
https://gitlab.com/hsn10/drand48

This is free and unencumbered software released into the public domain.
SPDX-License-Identifier: Unlicense OR CC0-1.0

For more information, please refer to <http://unlicense.org/>
*/

const DRAND48_NUMBERS: [f64; 40] = [
    0.37702568651093671,
    0.61423207130016522,
    0.57355920275780292,
    0.24912209328881119,
    0.87928458828271872,
    0.24765644011493748,
    0.92441303669178509,
    0.80555671224745851,
    0.014083361942912376,
    0.21886999375487903,
    0.84366486898379023,
    0.57466403417263479,
    0.21859070941080816,
    0.94239542105948715,
    0.83572678671088951,
    0.77823153263317835,
    0.52524201871785081,
    0.14172374538523513,
    0.64607604552879749,
    0.083946254876543946,
    0.90404830716751761,
    0.5554588670388938,
    0.23138546574741881,
    0.61145978163053627,
    0.92377363766738441,
    0.84066980989729245,
    0.48288483228689572,
    0.090734843766348661,
    0.49248787659580628,
    0.650608503405536,
    0.95375748438146601,
    0.79829372254715025,
    0.57065012958321759,
    0.66443082006171039,
    0.34954354774414398,
    0.17589252136810529,
    0.015644335386884478,
    0.62561513756837428,
    0.80729448578219021,
    0.72184867448159906,
];

#[test]
fn drand_srand48_minus() {
   let mut g = super::srand48(-1234567);
   for i in 0..DRAND48_NUMBERS.len() {
      assert_eq!(g.drand48(), DRAND48_NUMBERS[i], "array item no. {} failed", i);
   }
}

#[test]
fn drand_frand48_minus() {
   let mut g = super::srand48(-1234567);
   let epsilon = 0.000_000_1_f32; // 1e-7
   for i in 0..DRAND48_NUMBERS.len() {
      assert!( (g.frand48() - DRAND48_NUMBERS[i] as f32).abs() < epsilon, "array item no. {} failed", i);
   }
}