There are many algorithms for generating random numbers, differing from one another in the extent to which they exhibit the following desirable properties:
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.
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.
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
To see how the multiplicative congruential algorithm works, consider the following example:
The process yields the sequence
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:
giving
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:
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:
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:
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.
These are multiplied together to produce a product having eight digits.
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,
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:Created: 12-Oct-2003 — Last update: 15-Oct-2003 |