Skip to Content
Hands-On Data Structures and Algorithms with Rust
book

Hands-On Data Structures and Algorithms with Rust

by Claus Matzinger
January 2019
Intermediate to advanced
316 pages
8h 8m
English
Packt Publishing
Content preview from Hands-On Data Structures and Algorithms with Rust

Wichmann-Hill

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Data Structures and Algorithms in Rust

Hands-On Data Structures and Algorithms in Rust

Matthew Stoodley

Publisher Resources

ISBN: 9781788995528Supplemental Content