Section II: Linear Congruential Generator I   < < Index > >

 

In the following we shall consider methods for generating a sequence of random real numbers Un, uniformly distributed between zero and one. In other words, every number in the sequence is in [0,1) and the chance of being any number of [0,1) is equal. Since a computer can represent a real number with only finite accuracy, we shall actually be generating integers Xn between zero and some number m; the fraction

Un = Xn/m

will then lie between zero and one.

One of the most successful random number generators known today are special cases of the following scheme, which is called the linear congruential method. We choose four "magic numbers":

X0 , the starting value; X0 0 .
a, the multiplier; a 0.
c, the increment; c 0.
m, the modulus; m > X0, m > a, m > c.

 

The desired sequence of random numbers < Xn > is then obtained by setting

Xn+1 =(aXn + c) mod m,   n 0.

Xn is chosen to be in [0, m-1], n 0.

 

This is called a linear congruential sequence.

For example, the sequence obtained when X0 = a = c = 7, m = 10, is

7, 6, 9, 0, 7, 6, 9, 0, ...

As this example shows, the sequence is not always "random" for all choices of X0, a, c, and m; the way of choosing these values appropriately is the most important part of this method.

Because Xn+1 is determined by Xn, so once some number in the sequence get repeated, the sequence will get into a cycle. And because there are only m possible different values for Xn's, so the sequence will get into a cycle in at most m steps and the period is at most of length m.

It's very reasonable that we want the sequence to have long period so it might look random. So m is chosen to be very big, e.g. 231.

The special case c = 0 deserves explicit mention, since the number generation process is a little faster in this case. Lehmer's original generation method had c = 0, although he mentioned c 0 as a possibility. The terms multiplicative congruential method and mixed congruential method are used by many authors to denote linear congruential methods with c = 0 and c 0.

In the case of multiplicative congruential method, it's easy to see Xn = 0 should not be allowed, otherwise the sequence will be 0 forever afterwards. So the period is at most m-1. We can express Xn as anX0 . Notice that X0 0, so period of the sequence is the smallest positive value of k for which

  ak = 1 mod m. (3.1)

The Euler-Fermat Theorem states that if a and m are relatively prime, then aφ(m) = 1 mod m, where φ(m) is the Euler's totient function,meaning the number of positive integers less than or equal to n that are coprime to n. The period, therefore, can be no greater than φ(m). For a given value of m, we seek a such that k in equation (3.1) is φ(m). Such a number a is called a primitive root modulo m .(See [3], or other texts on number theory for general discussions of primitive roots)

For example, consider m = 31 and a = 7, 715 =1 mod 31, but φ(31) = 30, so 7 is not a primitive root modulo 31. If we consider a = 3, we will find it's a primitive root modulo 31, so the sequence will have period 30.

It turns out that m has a pimitive root if and only if m is equal to 1, 2, 4 or of the form 2αpβ, where p is an odd prime, α = 0 or 1, and β ≥ 1.

For general m, the period may not be as big as φ(m), but by choosing a properly, period that is big enough for use can still be achieved.

An an example of this kind of generator being used is in program RANDU, which for many years was the most widely used random number generator in the world. (Page 18-20 of [4])

The generator in RANDU is essentially (but not exactly the same as)

Xn+1 =65539Xn mod 231.

RANDU is still available at a number of computer centers and is used in some statistical analysis and simulation packages.

Exercise 2.1: Try the generator used in RANDU to see how does it work.

 

The case of mixed congruential method, i.e. c 0, is much more complicated. There is a powerful theorem as follows:

Theorem A: The linear congruential sequence has a period of length m if and only if
i) c is relatively prime to m;
ii)b = a-1 is a multiple of p, for every prime p dividing m;
iii)b is a multiple of 4, if m is a multiple of 4.

The proof of the theorem is left out here and can be found in Page 15-18 of [1].

Exercise 2.2: Give several examples of (c, m, a) satisfying the conditions of Theorem A and program the method with the tuples you find. Do they work well?
Exercise 2.3: Give an example of (c, m, a) satisfying Theorem A but yeilds a sequence that obviously not random. So what other criteria besides long period should be imposed?

 

Back to MEC Homepage Previous Section Back to Index Next Section