An extended approach to the LCG was taken by Brian Wichmann and David Hill when they invented their random number generator. It is based on the LCG, but uses three of them modified and combined by (magic) prime numbers.
These numbers, when added together, produce a sequence that is 6,953,607,871,644 (or 6.95 * 1012) numbers long, which means that calling the PRNG after this number of calls will make it start over:
const S1_MOD: f32 = 30269f32;
const S2_MOD: f32 = 30307f32;
const S3_MOD: f32 = 30323f32;
pub struct WichmannHillRng {
s1: f32,
s2: f32,
s3: f32,
}
impl WichmannHillRng {
fn new(s1: f32, s2: f32, s3: f32) -> WichmannHillRng {
WichmannHillRng {
s1: s1,
s2: s2,
s3: s3,
}
}
pub fn seeded(seed: u32) -> WichmannHillRng {
let t = seed;
let s1 = (t % 29999) as f32;
let s2 = (t % 29347) as f32;
let s3 = (t % 29097) as f32;
WichmannHillRng::new(s1, s2, s3)
}
pub fn...