Wichmann–Hill


Wichmann–Hill is a pseudorandom number generator proposed in 1982 by Brian Wichmann and David Hill. It consists of three linear congruential generators with different prime moduli, each of which is used to produce a uniformly distributed number between 0 and 1. These are summed, modulo 1, to produce the result.
Summing three generators produces a pseudorandom sequence with cycle exceeding. Specifically, the moduli are 30269, 30307 and 30323, producing periods of 30268, 30306 and 30322. The overall period is the least common multiple of these: 30268×30306×30322/4 =. This has been confirmed by a brute-force search.

Implementation

The following pseudocode is for implementation on machines capable of integer arithmetic up to :
= function is
// s1, s2, s3 should be random from 1 to 30,000. Use clock if available.
s1 := mod
s2 := mod
s3 := mod
r := mod
For machines limited to 16-bit signed integers, the following equivalent code only uses numbers up to 30,323:
= function is
// s1, s2, s3 should be random from 1 to 30,000. Use clock if available.
s1 := 171 × mod − 2 × floor
s2 := 172 × mod − 35 × floor
s3 := 170 × mod − 63 × floor
r := mod
The seed values s1, s2 and s3 must be initialized to non-zero values.