Random number generation
Initially well-stirred urn
Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin-John Von Neumann
Round numbers are always false- Samuel Johnson(1950)
Mechanical devices
ERNIE-picked lottery winner
Electric circuits based on randomly pulsating vacuum tubes
Difficulties
Was this random
Could not reproduce results
Von Neumann-1940.s Midsquare rule
For 8 digit number- square it and take middle 4 numbers.
7182 -> 51581124 -> 5811 -> 33767721 ->7677
Tends to degenerate to zero
Not "unpredictable . which is really true of all random number generators
Tends to short cycles
Forsythe tried 16 starting numbers and found 12 of them led to sequences ending with the cycle 6100,2100,4100,8100,6100
Good generators
Need separate streams for arrivals and departures
2 and 3 are easy, 4 now common, 1 is the problem
:Most are linear congruential generators of the form
Z(I)= (a Z(I-1)+ c) mod m
Z(0) is the seed and a, c, m are given constants
Want constants to be nonnegative and a<m, c<m, z(0) <m
If u= Z(I)/m get in [0,1]
But only get 0,1/m, 2/m, .(m-1)/m
If m is small then we miss a whole range
Usually take m >= 109
Tend to get looping.
If Z(I) = (5Z(I-1)+3) mod 16 with Z(0)=7
Get 7 6 1 8 11 10 5 12 15 14 9 0 3 2 13 4 7 6 1 8
Looping with full cycle
But with m=381, a=19 c=1 get 0 1 20 0 1 20
To get full period (1962) Hull + Dubell
(1) m and c must be relatively prime
(2) If q divides m, q a prime number then q must divide a-1
(3) If 4 divides m, 4 must divide a-1
Division by m is time consuming and thus one sometimes takes m =2b for a b bit machine
Assume a 4 bit machine if do Z(I) = (5Z(I-1)+3) mod 16 starting with 5 get
5*5+3 =28
28 =11100, modulus 16 =12, drops left most bit
But with C++ can not ignore overflows so break multiplication into pieces.
To multiply p*q = (104p(1) + p(2) ) (104q(1) + q(2) )
The Theorem suggests for m =2b that c is odd and a-1 is divisible by 4
If a = 2l-1 for some l
Then a Z(I-1) = 2l Z(I-1)+Z(I-1)
i.e. shifting by l bits and then adding.
But Knuth says this does not give good statistics
How about setting c=0- get multiplicative generator
If m =2b get period of 2b-2. So ¼ numbers are not hit and we do not know where they are- there might be large gaps.
If a = 2l+j which is just shifts + j adds, get really poor property which is just what RANDU gives