Generation of Random Numbers
(From Ecker et al. [1988, p 468].)
†: indicates a questionable statement;  **: a note.

   There are many algorithms for generating random numbers, differing from one another in the extent to which they exhibit the following desirable properties:

  1. Long period of repetition.
  2. Apparent statistical independence of successive numbers.
  3. Uniform distribution.
  4. Speed.
  5. Repeatability.

   In relation to (a), it is desirable to complete a simulation without having the random numbers begin to repeat.  As to (b), independnce is necessary to ensure that the pseudorandom sequence is interchangeable with a truly random one.  As to (c), this is convenient because values from a uniform distribution are easy to transform into values from any arbitrary probability distribution that might be desired.  About (d), real simulations typically require a great many random numbers, so the speed with which an algorithm can be executed might have a big influence on the computer time consumed.  Usually, simplicity is the key to high speed.  About (e), although it is important for the sequence to be pseudorandom, it should be possible to use the same pseudorandom sequence from one run of a simulation to the next.  The main reason for this is so that it is possible to debug the computer program that performs the simulation.  (…) In order to produce pseudorandom sequences having good statistical properties, it is inevitably necessary to sacrifice speed.  Thus, the selection of a suitable random-number generator for a given simulation can be a nontrivial task. (** Some of these methods are shown in this site.)

The Multiplicative Congruential Algorithm
   The simplest random-number generator is the multiplicative congruential algorithm.

uk+1 = (m.uk) mod p.

All the numbers used in the algorithm are nonnegative integers.  The parameter m is called the multiplier, the parameter p is called the modulus, and the starting number u0 is called the seed.  The heart of the algorithm is the recursion formula telling how each number in the sequence is generated from the previous one†.  (** Why not several previous ones ? Speed ?) The notation "mod p" in this formula refers to the result of an integer division.

x mod p = remainder left over after dividing x by p

If no uk is zero, the integers that can be generated range from 1 through p − 1, so uk  − 1 ranges from 0 through p − 2 and corresponding real numbers rk in the range [0, 1] can be obtained as

rk = (uk − 1) ⁄ (p − 2)

   To see how the multiplicative congruential algorithm works, consider the following example:

p = 17       m = 5       u0 = 7

The process yields the sequence

7, 1, 5, 8, 6, 13, 14, 2, 10, 16, 12, 9, 11, 4, 3, 15, 7, 1, 5, 8, …

The repetition is obvious, with a period of 16 numbers.  The period is always less than the parameter p, so p should be chosen as the largest value that can conveniently be used.  In particular, if the computer word length is w bits and we chose p = 2w, the multiplication in the recursion formula yields a two-word result, the low-order word of which is the product modulo 2w.  The choice p = 2w−1 permits the desired value to be found almost as easily, and it is therefore also frequently used.
   It is possible for the period of repetition to be much less than p if the multiplier m is inauspiciously chosen, and to get the longest possible period, p − 1, m should be chosen in such a way that m − 1 is a multiple of every prime number that divides p without a remainder.  It is also essential that no integer multiple of m be equal to p, or else the period of repetition is only one number long:

p = 10       m = 5       u0 = 6

giving

5, 5, 5, 5, …

   Finally, for the sequence generated to have good statistical properties, m should be close to the square root of p, and the sequence used in a simulation should be no longer than the square root of the period of repetition.
   In practice, even if these rules are followed, the choice of values for p and m must be guided by statistical analysis of the sequences actually produced.  The most commonly used multiplicative congruential generator, which is available on many computer systems by the subroutine name RANDU, has p = 231 = 2 147 483 648 and m = 216 + 3 = 65 539.  These choices yield an algorithm that has a period of 229 (500 million) numbers and runs very fast on computers having a word length of 32 bits.  However, the sequence it produces has the property that each number is related to the two previous ones by a simple formula, and this strong serial correlation makes the sequence generated by RANDU unsuitable for many simulations.
   Two much better generators that are available in widely used commercial scientific subroutine packages have the following parameters:

p = 231 = 2 147 483 648       m = 1313 = 302 875 106 592 253;             p = 231 − 1 = 2 147 483 647       m = 75 = 16 807

The generator on the right runs slower than RANDU because the modulus operation is much easier to perform using p = 231 than with p = 231 − 1. (** The one on the left is incompatible with the standard scientific computer language; run "constants" on Alfa.)

Other Uniform Random-Number Generators
   Improved statistical properties can be obtained by adding a constant term (** Compare with Ravindran et al. [1987].) >; to the multiplicative congruential recursion formula, as follows:

uk+1 = (a + m.uk) mod p.

The number a is called the increment, and an algorithm that uses this recursion formula is called a mixed or linear congruential generator.  As in the case of the multiplicative congruential generator, p should be the largest value that can conveniently be used.  The increment a should obviously be nonzero, but the other considerations involved in picking good values for a and m are rather complicated.  One published algorithm uses the followin parameter values:

p = 231 = 2 147 483 648; mp(π⁄8) + 5 = 843 314 861; ap(3 − √3) ⁄ 6 = 453 816 693

This generator has excellent statistical properties, and although it runs slower than RANDU because of the extra addition in the recursion formula, it is faster on most machines with 32-bit words than multiplicative congruential generators having p >232 or p not a power of 2.
   Another commonly used random-number generator having good statistical properties is the GPSS algorithm (from General Purpose System Simulator, a next-event simulation programming language).  Suppose that it is desired to generate random numbers from .0000 to .9999.  (The algorithm is actually carried out using binary numbers on a computer.)  (** So this is mainly for illustrative purpose.) >; We begin with a multiplier m, which is fixed, and a seed u0.

m = 5167; u0 = 3729

These are multiplied together to produce a product having eight digits.

m u0 = 19 2677 43 = 1926 7743

The middle four digits of this product are used to form the first random number r1, and the rightmost four digits are used as u1.  Thus,

r1 = .2677; u1 = .7743

Next the product m u1 is formed, its middle four digits are used as the digits of r2, its rightmost four digits become u2, and so forth.

Reference:
• Ecker, Joseph G., Michael Kupferschmid, 1988, "Introduction to Operations Research", John Wiley & Sons, New York, NY, USA
• Ravindran, A., Don T. Phillips, James J. Solberg, 1987, "Operations Research: principles and practice", 2.nd ed., John Wiley & Sons, New York, NY, USA
 

Created: 12-Oct-2003 — Last update: 15-Oct-2003