Wichmann-Hill
Wichmann-Hill is a pseudorandom number generator proposed in 1982 by Brian Wichmann and David Hill.[1] In its core, numbers are generated by taking the fractional part of a sum of rectangularly distributed numbers from imperfect algorithms. As the addition of fractional parts of numbers will be rectangularly distributed if only one of the number is rectangular, the method is an appropriate generator. In its crude form, three number generators are used to create a pseudorandom sequence with cycle exceeding .[2] A brute-force computation result of AS183[3] shows that the length of cycle is 6953607871644.
Implementation
The following pseudocode is for implementation on machines capable of integer arithmetic up to 30323.
[r, s1, s2, s3] = function(s1, s2, s3)
% s1, s2, s3 should be random from 0 to 30,000. Use clock if available
s1 = 171 * mod(s1, 177) - 2 * (s1/177)
s2 = 172 * mod(s2, 176) - 35 * (s2/176)
s3 = 170 * mod(s3, 178) - 63 * (s3/178)
r = mod ( s1/30269 + s2/30307 + s3/30323 , 1)
On machines capable of integer arithmetic up to 5,212,632, the more compact version gives identical results
[r, s1, s2, s3] = function(s1, s2, s3)
% s1, s2, s3 should be random from 0 to 30,000. Use clock if available
s1 = mod ( 171 * s1, 30269 )
s2 = mod ( 172 * s2, 30307 )
s3 = mod ( 170 * s3, 30323 )
r = mod ( s1/30269 + s2/30307 + s3/30323 , 1)
References
- ↑ Wichmann, Brian; Hill, David (1982). "Algorithm AS 183: An Efficient and Portable Pseudo-Random Number Generator". Journal of the Royal Statistical Society. Series C (Applied Statistics), Vol. 31, No. 2 (1982), pp. 188-190.
- ↑ Wichmann, Brian; Hill, David (1982). "Correction: Algorithm AS 183: An Efficient and Portable Pseudo-Random Number Generator". Journal of the Royal Statistical Society. Series C (Applied Statistics), Vol. 33, No. 1 (1984), p. 123.
- ↑ Rikitake, Kenji. "AS183 PRNG algorithm internal state calculator in C".