Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

3

LINEAR CONGRUENTIAL
GENERATORS

Random numbers fall mainly in the planes.


- George Marsaglia (1968)

The linear congruential method is the most popular algorithm for random num-
ber generation in the field of computer simulations. The linear congruential
generator (LeG) is defined by
Xn = aXn- 1 +c (modM),
Xn

where a, c, and M are integers and X n , n = 1,2, ... , is a sequence of integers with
o~ Xn < M. The normalized sequence Un, n = 1,2, ... , is a random number
sequence in [0,1). The following results tell us how to choose the parameters
a, c, and M to obtain the maximal period lengths.

For the case c ¥ 0, we have

Theorem 3.1 An LeG with the parameters (a, c, M) has period length M if
and only if

(i) gcd(c, M) = 1;

(ii) a = 1 (modp) for every prime p dividing M;

(iii) a = 1 (mod4) if M is a multiple of 4.

For the case c = 0, which is more important in practice, we have

S. Tezuka, Uniform Random Numbers


© Kluwer Academic Publishers 1995
58 Chapter 3

Theorem 3.2 An LeG with the parameters (a, 0, M) has a maximal period
length A(M) if and only if

(i) gcd(Xo, M) = 1;
(ii) a is a primitive element modulo M.

In the 1960's, the most popular choice of parameters was c = 0 and M =


2w , w ~ 4; in this case a = 3 or 5 (mod8) is the necessary and sufficient con-
dition for the maximal period. (For example, RANDU, IBM scientific library
subroutine widely used allover the world in the 1960s, used the parameters
a = 65539, c = 0, and M = 231.) However, it is now known that this choice
is problematic because of the non-randomness of the low-order bits of X n • To
be precise, the least significant I bits of X n , n = 1,2, ... , have a period of at
most 21. Recently, therefore, a common choice has been to take M as prime
and a as a primitive root modulo M. Onfl of the most popular generators of
this type is the so-called GGL, the IBM random number subroutine [49]' in
which a = 75 , C = 0, and M = 231 - 1. We need to notice that if M is a
prime and a is primitive modulo M, then the period becomes M - 1 whatever
c is. This is because if we put Yn = Xn + c/(a - 1), we have a homogeneous
form Y n = aYn - 1 (modM). Notice also that for a prime M the maximum
period M is attained only when a = 1 and gcd(c, M) = 1, which, unfortunately,
produces a non-random-looking sequence, such as 1,2,3, ... , when c = 1.

On an L-:bit word computer (L is usually 32), the multiplication of X by a often


causes an overflow, since all single-precision integers are between _2 L - 1 and
2 L - 1 -1. We therefore need a technique to avoid any overflow in the calculation
of aX (modM). One idea is based on the following: Let q = [M/a] and
r = IMla. Then we have

aX = alXlq - [~] r (modM).

If ar < M, it is easy to see that no overflow occur when we use the RHS. On
the basis of this idea, Schrage (see [16]) implemented the generator GGL in
an efficient and portable way.

In many applications, we need multiple independent streams of random number


sequences. One approach to handling this problem is to partition an entire
period of a single sequence into many long disjoint subsequences. In order to do
that, a random number generator must quickly jump ahead to the beginnings of
different subsequences and jump back to the previous sequence. This property

You might also like