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/>
*/

#![allow(non_upper_case_globals)]

/// seeded with hard 3x zero
const mrand48_000: [i32; 40] = [
    0,
    4232237,
    178803790,
    758674372,
    1565954732,
    392261992,
    396415378,
    2092582042,
    -2032592072,
    1951776693,
    1001493746,
    -724596254,
    -293211053,
    -1855169837,
    -1906560325,
    218321409,
    -1000507651,
    81238462,
    1083876924,
    1280747107,
    -532658120,
    -2011947947,
    -342476647,
    -2081207358,
    -814199298,
    809258813,
    -488275746,
    -1844198745,
    329744245,
    -793392635,
    -64892586,
    508316721,
    -455670687,
    -925635702,
    433432093,
    1087960852,
    85219289,
    1625118877,
    -1379211020,
    -1370425116,
];

/// seeded with srand48(0)
const mrand48_srand48_0: [i32; 40] = [
    733700828,
    -1074162815,
    413913109,
    -556347614,
    -1815467615,
    -919985179,
    -1322016045,
    1583839069,
    -541577867,
    -1094808216,
    1915752592,
    1519251063,
    -1148819433,
    1117644984,
    1693478868,
    -958679860,
    -665569017,
    -1821975806,
    -1221752431,
    356500522,
    1957754020,
    472217971,
    -1953230765,
    1677986043,
    -1852911499,
    -175808261,
    -568142155,
    700893609,
    1183301830,
    1118242387,
    -326010602,
    1872273469,
    -904258697,
    548110913,
    353070733,
    -254940599,
    109843471,
    662330906,
    1641461017,
    664589064,
];

/// seeded with srand48(0b1010010001);
const mrand48_custom: [i32; 40] = [
    1236713625,
    -1435219206,
    1095672986,
    -1212757565,
    -792689106,
    -1389217298,
    717036200,
    -839591154,
    -878139950,
    -603890943,
    593825973,
    -1537459144,
    -1910183612,
    1940215521,
    232729929,
    1351974301,
    -981041148,
    -1798151493,
    2054326614,
    -687363829,
    -1411674511,
    1853039548,
    -1494276248,
    1575336684,
    -994960878,
    1919600340,
    928786970,
    523766186,
    1714218803,
    251285692,
    1739488715,
    973750094,
    1930435508,
    870083130,
    -120329838,
    -900937366,
    -294339812,
    832253091,
    1604959086,
    1585636153,
];

const mrand48_srand_minus1234567: [i32; 40] = [
    1619312993,
    -1656860638,
    -1831549278,
    1069971243,
    -518468746,
    1063676310,
    -324643536,
    -835127562,
    60487578,
    940039465,
    -671454275,
    -1826804064,
    938839948,
    -247409783,
    -705548079,
    -952488315,
    -2039070004,
    608698851,
    -1520091810,
    360546419,
    -412109383,
    -1909289628,
    993793008,
    -1668767532,
    -327389734,
    -684317956,
    2073974562,
    389703186,
    2115219323,
    -1500625052,
    -198610093,
    -866321866,
    -1844043652,
    -1441258654,
    1501278106,
    755452626,
    67191908,
    -1607970741,
    -827663882,
    -1194650847,
];



#[test]
fn mrand_000() {
   let mut g = super::DRAND48::seed(0);
   for i in 0..mrand48_000.len() {
      assert_eq!(g.mrand48(), mrand48_000[i], "array item no. {} failed", i);
   }
}

#[test]
fn mrand_srand_0() {
   let mut g = super::DRAND48::seed(0|0x_330e);
   for i in 0..mrand48_srand48_0.len() {
      assert_eq!(g.mrand48(), mrand48_srand48_0[i], "array item no. {} failed", i);
   }
}

#[test]
fn mrand_srand48_check_0() {
   let mut g = super::srand48(0);
   for i in 0..mrand48_srand48_0.len() {
      assert_eq!(g.mrand48(), mrand48_srand48_0[i], "array item no. {} failed", i);
   }
}

#[test]
fn mrand_srand48_custom() {
   let mut g = super::srand48(0b1010010001);
   for i in 0..mrand48_custom.len() {
      assert_eq!(g.mrand48(), mrand48_custom[i], "array item no. {} failed", i);
   }
}

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