Generation of Random Numbers

Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.
John von Neumann (1951)

Up to now we have not discussed where the ``random numbers'' come from or indeed what we mean operationally by a random number. First randomness is a property of an infinite sequence xi with i = 1, 2, . . . . It is impossible to tell whether a single number is random or not. Random is a negative property, it is the absence of any order.

Note that there are three types of so-called random numbers.

In this section we will only discuss the uniform distribution, x, is either uniformly distributed in the range (0, 1) or x is an integer in [1, 2M]. (M is the number of bits). For simplicity, assume the latter representation. Then we can say the sequence is not random if knowing the previous values, allows you to predict something about the next value, (other than it is one of the allowed integers). With a random sequence, the predictions of even a very clever person are not better than average.

What are some of the desired properties of random numbers?
Uncorrelated, deterministic, long-periods between repeats, uniform converage of range, efficiency of algorithm.

< f1(xi+1) f2(xi+2) . . . fk(xi+k) > = < f1(xi+1) > < f2(xi+2) > . . . < fk(xi+k) >

or for any set of functions f. The average is over all internal states of the random number generator. It turns out that Monte Carlo simulations of statistical mechanics can be sensitive to very long range correlations. Which particular correlations they are sensitive to is not very obvious, so often the only real test to run the code for a case where the exact answer is know or alternatively to try several different PRNGs.

If all you are doing is one dimensional integrals, one doesn't have to worry about correlation.

Quasi random number generators give up correlation, so the sequence will be more uniform than a random sequence would be, and thereby converge to the mean value quicker than N-1/2. (reference Physics Today)



Types of Pseudo-random number generators (PRNG)

Some of the common types of random number generators are:

 

Seeds for PRNG

For debugging, as stated in class, the seed can be set to a known constant (such as a large prime (odd number)) for reproducibility of PRN sequence. Otherwise the initial seed of the RNG should be a random odd number. S.L. Anderson [``Random Number Generators on Vector Supercomputers and Other Advanced Architectures,'' SIAM Review, 32, 221-251 (1990)]. recommends setting initial seed to integer:
Io= iyr + 100*(imonth-1 + 12*(iday-1 + 31*(ihour + 24*(imin + 60*isec) ) ) )
where the variables are integer year (0-99), month, day, and time. To introduce maximum variation in the seed into the least significant digit, it has been suggested to invert the order of the variables (see Computational Science & Engineering Project) to the "second of the century" by
Io= isec + 100*(imin + 60*(ihr + 24*(iday-1 + 31*(imon -1 + 12*iyr) ) ) )
and make Io = ior(Io,1) (in Fortran) to make sure it is odd!

Overflows and Negative Integers must be dealt with carefully. Recall that a (and m) is set large to provide sufficient randomness (and long periods). But, if two 31-bit numbers are multiplied, a 62-bit number is generated (an overflow) and the 32-bit (which is the sign bit for the mantissa) can be set (a negative number). Negative numbers then occur about half the time. One method is to use a bit mask to handle the most significant 32-bit and set it to `0'. A logical AND operation can be performed on the random, negative integer by using the bit mask imask=z'7fffffff' (which is zero followed by 31 ones in base-2). In Fortran, this is done by In = iand(In, imask). But masking only works when m is a powers of two, or else iand destroys sequence. In C, one can use unsigned integer and avoid the sign bit problem altogether.

 

Parallel PRNG

All of the above generators can be generalized to parallel computation. That presents some interesting issues to ensure that each processor has a completely independent generator. We have developed SPRNG a parallel random number library.
 

Testing Generators

Statisticians have invented many tests to tell if sequences are random such as those given by Knuth.. The most complete test is to examine how uniform n-tuples (or vectors) are.You will do this in the homework exercise. If the generator is random, equal numbers of vectors will be in each bin within statistical fluctuations. These tests of random number generators (RNG) are not adequate in determining completely the usefulness of a particular RNG because they only test numbers 5-10 at a time. But much longer sequences can be important in applications. Thus the construction and testing of prng is an art and not a science.The best test is to use several different generators on your application and see if the results are independent of the generator.But for these to be a good test, your runs have to be as long as the production runs. (Why?) SPRNG allows you to switch the generator just by changing a link argument in the Makefile.

 

See other on-line material:

Random Numbers on the Web

See Tutorial on RNG

 

References:

D. Knuth, Art of Computer Programming, Vol2. Seminumerical Algorithms, Second edition. Addison-Wesley, Reading, Massachusetts, 1981.

W.H. Press and S.A. Teukolsky, Numerical Recipes

Portable PRNG: George Marsaglia and Arif Zaman, Comput. Phys. 8, 117 (1994)
(From Physics Resource Link download Computer in Physics Articles)

P. Coddington, Tests of random number generators using Ising model simulations . Int. J. of Mod. Phys. C, 7(3):295-303, 1996.

Srinivasan, A., D. M. Ceperley and M. Mascagni, "Random Number Generators for Parallel Applications" in Monte Carlo Methods in Chemical Physics, Vol. 105, Advances in Chemical Physics, eds. D. M. Ferguson, J. I. Siepmann and D. G. Truhlar,Wiley (1999).

©D.D. Johnson, 1999, D. M. Ceperley, 2000, DDJ/DMC 2001