Wichmann–Hill is a
pseudorandom number generator
A pseudorandom number generator (PRNG), also known as a deterministic random bit generator (DRBG), is an algorithm for generating a sequence of numbers whose properties approximate the properties of sequences of random numbers. The PRNG-generate ...
proposed in 1982 by
Brian Wichmann
Brian (sometimes spelled Bryan in English) is a male given name of Irish and Breton origin, as well as a surname of Occitan origin. It is common in the English-speaking world.
It is possible that the name is derived from an Old Celtic word meani ...
and David Hill. It consists of three
linear congruential generator
A linear congruential generator (LCG) is an algorithm that yields a sequence of pseudo-randomized numbers calculated with a discontinuous piecewise linear equation. The method represents one of the oldest and best-known pseudorandom number generat ...
s with different
prime
A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways ...
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
In arithmetic and number theory, the least common multiple, lowest common multiple, or smallest common multiple of two integers ''a'' and ''b'', usually denoted by lcm(''a'', ''b''), is the smallest positive integer that is divisible by bot ...
of these: 30268×30306×30322/4 = . This has been confirmed by a
brute-force search
In computer science, brute-force search or exhaustive search, also known as generate and test, is a very general problem-solving technique and algorithmic paradigm that consists of systematically enumerating all possible candidates for the soluti ...
.
Implementation
The following
pseudocode
In computer science, pseudocode is a plain language description of the steps in an algorithm or another system. Pseudocode often uses structural conventions of a normal programming language, but is intended for human reading rather than machine re ...
is for implementation on machines capable of integer arithmetic up to :
, s1, s2, s3= function(''s1'', ''s2'', ''s3'') is
''// s1, s2, s3 should be random from 1 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.0 + ''s2''/30307.0 + ''s3''/30323.0, 1)
For machines limited to 16-bit signed integers, the following equivalent code only uses numbers up to :
, s1, s2, s3= function(''s1'', ''s2'', ''s3'') is
''// s1, s2, s3 should be random from 1 to 30,000. Use clock if available.''
''s1'' := 171 × mod(''s1'', 177) − 2 × floor(''s1'' / 177)
''s2'' := 172 × mod(''s2'', 176) − 35 × floor(''s2'' / 176)
''s3'' := 170 × mod(''s3'', 178) − 63 × floor(''s3'' / 178)
''r'' := mod(s1/30269 + s2/30307 + s3/30323, 1)
The seed values
s1
,
s2
and
s3
must be initialized to non-zero values.
References
{{DEFAULTSORT:Wichmann-Hill
Pseudorandom number generators