January 2019
Intermediate to advanced
316 pages
8h 8m
English
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 ...