Skip to content

7 Random-Number Generation

Random numbers are a necessary basic ingredient in the simulation of almost all discrete systems. Most computer languages have a subroutine, object, or function that will generate a random number. Random numbers are used to generate event times and other random variables in simulation languages. In this chapter, the generation of random numbers and their subsequent testing for randomness is described.

1 Properties of Random Numbers

A sequence ofrandom numbers,R1,R2,…,R_{1} , R_{2} , \ldots ,, must have two important statistical properties: uniformity and independence. Each random number RiR_{i} must be an independent sample drawn from a continuous uniform distribution between zero and 1—that is, the pdf is given by

f(x)={1,0≤x≤10,otherwise f (x) = \left\{\begin{array}{l l} 1, & 0 \leq x \leq 1 \\ 0, & \text{otherwise} \end{array} \right.

This density function is shown in Figure 1. The expected value of each RiR_{i} is given by

E(R)=∫01xdx=x22∣01=12 E (R) = \int_{0} ^ {1} x d x = \left. \frac {x^{2}}{2} \right| _ {0} ^ {1} = \frac {1}{2}

Figure 1 pdf for random numbers.

and the variance is given by

V(R)=∫01x2dx−[E(R)]2=x33∣01−(12)2=13−14=112 V (R) = \int_{0} ^ {1} x^{2} d x - [ E (R) ] ^ {2} = \left. \frac {x^{3}}{3} \right| _ {0} ^ {1} - \left(\frac {1}{2}\right) ^ {2} = \frac {1}{3} - \frac {1}{4} = \frac {1}{12}

Some consequences of the uniformity and independence properties are the following:

  1. If the interval [0, 1] is divided into n classes, or subintervals of equal length, the expected number of observations in each interval is N/n,N / n , where N is the total number of observations.

  2. The probability of observing a value in a particular interval is independent of the previous values drawn.

In the next section we describe desirable properties of methods that produce random numbers to drive simulations.

2 Generation of Pseudo-Random Numbers

Notice that the title of this section has the word “pseudo” in it. “Pseudo” means false, so false random numbers are being generated! In this instance, “pseudo” is used to imply that the very act of generating random numbers by a known method removes the potential for true randomness. I the method is known, the set of random numbers can be repeated. Then an argument can be made that the numbers are not truly random. The goal of any generation scheme, however, is to produce a sequence of numbers between 0 and 1 that simulates, or imitates, the ideal properties of uniform distribution and independence as closely as possible.

To be sure, in the generation of pseudo-random numbers, certain problems or errors can occur. These errors, or departures from ideal randomness, are all related to the properties stated previously in Section 1. Some examples of such departures include the following:

  1. The generated numbers might not be uniformly distributed.

  2. The generated numbers might be discrete-valued instead of continuous-valued.

  3. The mean of the generated numbers might be too high or too low.

  4. The variance of the generated numbers might be too high or too low.

  5. There might be dependence as measured, for instance, by autocorrelation.

Departures from uniformity and independence for a particular generation scheme often can be detected by tests such as those described in Section 4. If departures are detected, the generation scheme should be dropped in favor of an acceptable generator. Generators that pass the tests in Section 4, and tests even more stringent, have been developed; thus, there is no excuse for using a generator that has been found to be defective.

Usually, random numbers are generated by a digital computer as part of the simulation. There are numerous methods that can be used to generate the values. Before we describe some of these methods, there are several important considerations that we should mention:

  1. The method should be fast. Individual computations are inexpensive, but simulation could require many millions of random numbers. The total cost can be managed by selecting a computationally efficient method of random-number generation.

  2. The method should be portable to different computers—and, ideally, to different programming languages. This is desirable so that the simulation program will produce the same results wherever it is executed.

  3. The method should have a sufficiently long cycle. The cycle length, or period, represents the length of the random number sequence before previous numbers begin to repeat themselves in an earlier order. Thus, if 10,000 events are to be generated, the period should be many times that long.

A special case of cycling is degenerating. A method degenerates when the same random numbers appear repeatedly. Such an occurrence is certainly unacceptable. This can happen rapidly with some methods.

  1. The random numbers should be repeatable. Given the starting point (or conditions) it should be possible to generate the same set ofrandom numbers, completely independent ofthe system that is being simulated. This is helpful for debugging purposes and facilitates comparisons between systems. For the same reasons, it should be possible to easily specify differen starting points, widely separated, within the sequence.

  2. Most important, the generated random numbers should closely approximate the ideal statistical properties of uniformity and independence.

Inventing techniques that seem to generate random numbers is easy; inventing techniques tha really do produce sequences that appear to be independent, uniformly distributed random numbers is incredibly difficult. There is now a vast literature and rich theory on the topic, and many hours of testing have been devoted to establishing the properties of various generators. Even when a technique is known to be theoretically sound, it is seldom easy to implement it in a way that will be fast and portable. The goal of this chapter is to make the reader aware of the central issues in random-number generation, to enhance understanding, and to show some of the techniques that are used by those working in this area.

3 Techniques for Generating Random Numbers

The linear congruential method of Section 3.1 is the most widely used technique for generating random numbers, so we describe it in detail. We also report on an extension of this method that yields sequences with a longer period. Many other methods have been proposed, and they are reviewed in Bratley, Fox, and Schrage [1996], Law [2007], and Ripley [1987].

3.1 Linear Congruential Method

The linear congruential method, initially proposed by Lehmer [1951], first produces a sequence of integers,X1,X2,...X_{1} , X_{2} , . . .. between zero and m−1m - 1 by following a recursive relationship:

Xi+1=(aXi+c) mod m,i=0,1,2,…(1) X_{i + 1} = (a X_{i} + c) \bmod m, \quad i = 0, 1, 2, \dots\tag{1}

The initial value X0X_{0} is called the seed, a is called the multiplier, c is the increment, and m is the modulus. If c≠0c \neq 0 in Equation (1), then the form is called the mixed congruential method. When c=0,c = 0 ,, the form is known as the multiplicative congruential method. The selection of the values for a,c,m,a , c , m ,, and X0X_{0} drastically affects the statistical properties and the cycle length. Variations of Equation (1) are quite common in the computer generation of random numbers.

Notice that random integers are being generated rather than random numbers. These random integers should appear to be uniformly distributed on the integers zero to m.m .. Random numbers RiR_{i} between zero and 1 can then be generated by setting

Ri=Xim,i=1,2,…(2) R_{i} = \frac {X_{i}}{m}, \quad i = 1, 2, \ldots\tag{2}

An example will illustrate how this technique operates.

Example 1

Use the linear congruential method to generate a sequence of random numbers with X0=27,a=17X_{0} = 27 , a = 17c=43c = 43, and m=100m = 100 The sequence of seeds XiX_{i} and subsequent random numbers RiR_{i}, is computed as follows:

X0=27 X_{0} = 27 X1=(17⋅27+43) mod 100=502 mod 100=2 X_{1} = (17 \cdot 27 + 43) \bmod 100 = 502 \bmod 100 = 2 R1=2100=0.02 R_{1} = \frac {2}{100} = 0. 02 X2=(17⋅2+43) mod 100=77 mod 100=77 X_{2} = (17 \cdot 2 + 43) \bmod 100 = 77 \bmod 100 = 77 R2=77100=0.77 R_{2} = \frac {77}{100} = 0. 77 X3=(17⋅77+43) mod 100=1352 mod 100=52 X_{3} = (17 \cdot 77 + 43) \bmod 100 = 1352 \bmod 100 = 52 R3=52100=0.52 R_{3} = \frac {52}{100} = 0. 52

Recall that a=ba = b mod m provided that b−ab - a is divisible by m with no remainder; otherwise, the mod operation returns the remainder of b/mb / m. Thus,X1=502X_{1} = 502 mod 100=2100 = 2 because 502/100 equals 5 with a remainder of 2.

The ultimate test of the linear congruential method, as of any generation scheme, is how closely the generated numbers R1,R2,…R_{1} , R_{2} , \ldots. approximate uniformity and independence. There are, however, several secondary properties that must be considered. These include maximum density and maximum period.

First, notice that the numbers generated from Equation (2) assume values only from the set I={0,1/m,2/m,…,(m−1)/m}I = \{0 , 1 / m , 2 / m , \ldots , ( m - 1 ) / m \}, because each X is an integer in the set {0,1,2,…,m−1}\{0 , 1 , 2 , \ldots , m - 1 \}. Thus, each RiR_{i} is discrete on I, instead of continuous on the interval [0, 1]. This approximation appears to be of little consequence if the modulus m is a very large integer. (Values such as m=231−1m = 2^{31} - 1 and m=248m = 2^{48} are in common use in generators appearing in many simulation languages.) By maximum density is meant that the values assumed by Ri,i=1,2,…R_{i} , i = 1 , 2 , \ldots, leave no large gaps on [0, 1].

Second, to help achieve maximum density, and to avoid cycling in practical applications (i.e., recurrence ofthe same sequence ofgenerated numbers), the generator should have the largest possible period. Maximal period can be achieved by the proper choice of a,c,m.a , c , m ., and X0X_{0}[Law 2007].

For m a power of 2,^ {2 ,}, say m=2bm = 2^{b}, and c≠0.c \neq 0 ., the longest possible period is P=m=2bP = m = 2^{b} which is achieved whenever c is relatively prime to m (that is, the greatest common factor of c and m is 1) and a=1+4ka = 1 + 4 k, where k is an integer.

For m a power of 2,say⁡m=2b2 , \operatorname{s a y} m = 2^{b}, and c=0c = 0, the longest possible period is P=m/4=2b−2P = m / 4 = 2^{b - 2} which is achieved if the seed X0X_{0} is odd and if the multiplier a is given by a=3+8ka = 3 + 8 k or a=5+8ka = 5 + 8 k, for some k=0,k = 0 ,, 1, . . . .

For m a prime number and c=0.c = 0 ., the longest possible period is P=m−1P = m - 1, which is achieved whenever the multiplier a has the property that the smallest integer k such that ak−1a^{k} - 1 is divisible by m is k=m−1k = m - 1

Example 2

Using the multiplicative congruential method, find the period of the generator for a=13,m=26=a = 13 , m = 2^{6} =64, and X0=1,2,3X_{0} = 1 , 2 , 3, and 4. The solution is given in Table 1. When the seed is 1 or 3, the sequence has period 16. However, a period of length 8 is achieved when the seed is 2 and a period of length 4 occurs when the seed is 4.

In Example 2,m=26=64m = 2^{6} = 64 and c=0c = 0. The maximal period is therefore P=m/4=16.P = m / 4 = 16 .. Notice that this period is achieved by using odd seeds,X0=1X_{0} = 1 and X0=3;X_{0} = 3 ;; even seeds,X0=2X_{0} = 2 and X0=4X_{0} = 4 yield the periods 8 and 4, respectively, both less than the maximum. Notice that a=13a = 13 is of the form 5+8k5 + 8 k with k=1k = 1, as is required to achieve maximal period.

When X0=1X_{0} = 1, the generated sequence assumes values from the set {1,5,9,13,…,53,57,61}\{1 , 5 , 9 , 13 , \dots , 53 , 57 , 61 \} The gaps in the sequence of generated random numbers RiR_{i} are quite large (i.e., the gap is 5/64−1/645 / 64 - 1 / 64 or 0.0625). Such a gap gives rise to concern about the density of the generated sequence.

The generator in Example 2 is not viable for any application—its period is too short and its density is insufficient. However, the example shows the importance of properly choosing a,c,m,a , c , m , and X0X_{0} Table 1 Period Determination Using Various Seeds

iXiX_iXiX_iXiX_iXiX_i
01234
113263952
241185936
321426320
41734514
5295823
6575043
7371047
833235
9457
10927
115331
124919
136155
142511
15515
1613

Speed and efficiency in using the generator on a digital computer is also a selection consideration. Speed and efficiency are aided by use of a modulus, m, which is either a power of 2 or close to a power of 2. Since most digital computers use a binary representation of numbers, the modulo, or remaindering, operation of Equation (1) can be conducted efficiently when the modulo is a power of 2(i.e.,m=2b)2 ( {\mathrm{i . e . ,}} m = 2^{b} ). After ordinary arithmetic yields a value for aXi+c,Xi+1a X_{i} + c , X_{i + 1} is obtained by dropping the leftmost binary digits in aXi+ca X_{i} + c and then using only the b rightmost binary digits. The following example illustrates, by analogy, this operation using m=10bm = 10^{b}, because most human beings think in decimal representation.

Let X0=63,a=19,c=0,andm=102=100X_{0} = 63 , a = 19 , c = 0 , \mathrm{a n d} m = 10^{2} = 100, and generate a sequence of random integers using Equation (1).

X0=63X1=(19)(63) mod 100=1197 mod 100=97X2=(19)(97) mod 100=1843 mod 100=43X3=(19)(43) mod 100=817 mod 100=17⋮ \begin{array}{l} X_{0} = 63 \\ X_{1} = (19) (63) \bmod 100 = 1197 \bmod 100 = 97 \\ X_{2} = (19) (97) \bmod 100 = 1843 \bmod 100 = 43 \\ X_{3} = (19) (43) \bmod 100 = 817 \bmod 100 = 17 \\ \vdots \end{array}

When m is a power of 10, say m=10b.m = 10^{b} ., the modulo operation is accomplished by saving the b rightmost (decimal) digits. By analogy, the modulo operation is most efficient for binary computers when m=2bm = 2^{b} for some b>0,b > 0 ,

Example 4

The last example in this section is in actual use. It has been extensively tested [Learmonth and Lewis, 1973; Lewis et al..a l . ., 1969]. The values for a,c,a , c , and m have been selected to ensure that the characteristics desired in a generator are most likely to be achieved.

Let a=75=16,807,c=0a = 7^{5} = 16 {,} 807 , c = 0, and m=231−1=2,147,483,647m = 2^{31} - 1 = 2 , 147 , 483 , 647(a prime number). These choices satisfy the conditions that ensure a period of P=m−1P = m - 1(well over 2 billion). Further, specify the seed X0=123,457X_{0} = 123 , 457. The first few numbers generated are as follows:

X1=75(123,457) mod (231−1)=2,074,941,799 mod (231−1)X1=2,074,941,799R1=X1231=0.9662X2=75(2,074,941,799) mod (231−1)=559,872,160R2=X2231=0.2607X3=75(559,872,160) mod (231−1)=1,645,535,613R3=X3231=0.7662⋮ \begin{array}{l} X_{1} = 7^{5} (123, 457) \bmod (2^{31} - 1) = 2, 074, 941, 799 \bmod (2^{31} - 1) \\ X_{1} = 2, 074, 941, 799 \\ R_{1} = \frac {X_{1}}{2^{31}} = 0. 9662 \\ X_{2} = 7^{5} (2, 074, 941, 799) \bmod (2^{31} - 1) = 559, 872, 160 \\ R_{2} = \frac {X_{2}}{2^{31}} = 0. 2607 \\ X_{3} = 7^{5} (559, 872, 160) \bmod (2^{31} - 1) = 1, 645, 535, 613 \\ R_{3} = \frac {X_{3}}{2^{31}} = 0. 7662 \\ \vdots \end{array}

Notice that this method divides by m+1m + 1 instead of m;m ; however, for such a large value of m,m , the effect is negligible.

3.2 Combined Linear Congruential Generators

As computing power has increased, the complexity ofthe systems that we are able to simulate has also increased. A random-number generator with period 231−1⋅≈2×1092^{31} - \overset {\cdot} {1} \approx 2 \times 10^{9}, such as the popular generator described in Example 4, is no longer adequate for all applications. Examples include the simulation of highly reliable systems, in which hundreds of thousands of elementary events must be simulated in order to observe even a single failure event, and the simulation of complex computer networks, in which thousands of users are executing hundreds of programs. An area of current research is deriving generators with substantially longer periods.

One fruitful approach is to combine two or more multiplicative congruential generators in such a way that the combined generator has good statistical properties and a longer period. The following result from L’Ecuyer [1988] suggests how this can be done:

If Wi,1,Wi,2,…,Wi,kW_{i , 1} , W_{i , 2} , \ldots , W_{i , k} are any independent, discrete-valued random variables (not necessarily identically distributed), but one of them, say Wi,1W_{i , 1}, is uniformly distributed on the integers from 0 to m1−2m_{1} - 2 then

Wi=(∑j=1kWi,j) mod m1−1 W_{i} = \left(\sum_{j = 1} ^ {k} W_{i, j}\right) \bmod m_{1} - 1

is uniformly distributed on the integers from 0 to m1−2.m_{1} - 2 . To see how this result can be used to form combined generators, let Xi,1,Xi,2,…,Xi,kX_{i , 1} , X_{i , 2} , \ldots , X_{i , k} be the ith output from k different multiplicative congruential generators, where thejth generator has prime modulus mjm_{j} and the multiplier aja_{j} is chosen so that the period is mj−1m_{j} - 1. Then the jth generator is producing integers Xi,jX_{i , j} that are approximately uniformly distributed on the integers from 1 to mj−1m_{j} - 1 and Wi,j=Xi,j−1W_{i , j} = X_{i , j} - 1 is approximately uniformly distributed on the integers from 0 to mj−2.m_{j} - 2 .. L’Ecuyer therefore suggests combined generators of the form

Xi=(∑j=1k(−1)j−1Xi,j) mod m1−1 X_{i} = \left(\sum_{j = 1} ^ {k} (- 1) ^ {j - 1} X_{i, j}\right) \bmod m_{1} - 1

with

Ri={Xim1,Xi>0m1−1m1,Xi=0 R_{i} = \left\{\begin{array}{l l} \frac {X_{i}}{m_{1}}, & X_{i} > 0 \\ \frac {m_{1} - 1}{m_{1}}, & X_{i} = 0 \end{array} \right.

Notice that the 66(−1)j−1,5^ {66} ( - 1 ) ^ {j - 1 , 5} coefficient implicitly performs the subtraction Xi,1−1;X_{i , 1} - 1 ; for example, if k=2k = 2 then (−1)0(Xi,1−1)−(−1)1(Xi,2−1)=∑i=12(−1)j−1Xi,j\begin{array} {r} {( - 1 ) ^ {0} ( X_{i , 1} - 1 ) - ( - 1 ) ^ {1} ( X_{i , 2} - 1 ) = \sum_{i = 1} ^ {2} ( - 1 ) ^ {j - 1} X_{i , j}} \end{array} The maximum possible period for such a generator is

P=(m1−1)(m2−1)⋯(mk−1)2k−1 P = \frac {(m_{1} - 1) (m_{2} - 1) \cdots (m_{k} - 1)}{2^{k - 1}}

which is achieved by the generator described in the next example.

Example 5

For 32-bit computers, L’Ecuyer [1988] suggests combining k=2k = 2 generators with a1=40,014,a_{1} = 40 , 014 ,m1=2,147,483,563,a2=40,692m_{1} = 2 , 147 , 483 , 563 , a_{2} = 40 , 692, and m2=2,147,483,399m_{2} = 2 , 147 , 483 , 399. This leads to the following algorithm:

  1. Select seed X1,0X_{1 , 0} in the range [1, 2,147,483,562] for the first generator, and seed X2,0X_{2 , 0} in the range [1, 2,147,483,398] for the second.
j=0 j = 0
  1. Evaluate each individual generator.
X1,j+1=40,014X1,j mod 2,147,483,563 X_{1, j + 1} = 40, 014 X_{1, j} \bmod 2, 147, 483, 563 X2,j+1=40,692X2,j mod 2,147,483,399 X_{2, j + 1} = 40, 692 X_{2, j} \bmod 2, 147, 483, 399
  1. Set.
Xj+1=(X1,j+1−X2,j+1) mod 2,147,483,562 X_{j + 1} = \left(X_{1, j + 1} - X_{2, j + 1}\right) \bmod 2, 147, 483, 562
  1. Return.
Rj+1={Xj+12,147,483,563,Xj+1>02,147,483,5622,147,483,563,Xj+1=0 R_{j + 1} = \left\{\begin{array}{l l} \frac {X_{j + 1}}{2 , 147 , 483 , 563}, & X_{j + 1} > 0 \\ \frac {2 , 147 , 483 , 562}{2 , 147 , 483 , 563}, & X_{j + 1} = 0 \end{array} \right.
  1. Set j=j+1j = j + 1 and go to Step 2.

This combined generator has period (m1−1)(m2−1)/2≈2×1018( m_{1} - 1 ) ( m_{2} - 1 ) / 2 \approx 2 \times 10^{18}. Perhaps surprisingly, even such a long period might not be adequate for all applications. See L’Ecuyer [1996, 1999] and L’Ecuyer et al. [2002] for combined generators with periods as long as 2I9ˉ1≈3×10572 ^ {\mathsf {I} \mathsf {\bar {9}} 1} \approx 3 \times 10^{57}. One of these generators has been translated into Visual Basic for Applications and can be found in the spreadsheet RandomNumberTools.xls at www.bcnn.net.

3.3 Random-Number Streams

The initial seed for a linear congruential random-number generator (initial seeds, in the case of a combined linear congruential generator) is the integer value X0X_{0} that initializes the random-number sequence. Since the sequence of integers X ,X1,…,XP,X0,X1,… .X_{1} , \dots , X_{P} , X_{0} , X_{1} , \dots . produced by a generator repeats, any value in the sequence could be used to “seed” the generator.

For a linear congruential generator, a random-number stream is nothing more than a convenien way to refer to a starting seed taken from the sequence X0,X1,…,XPX_{0} , X_{1} , \ldots , X_{P}(for a combined generator, the stream is a reference to the starting seeds for all of the basic generators); typically these starting seeds are far apart in the sequence. For instance, if the streams are b values apart, then stream i could be defined by starting seed

Si=Xb(i−1) S_{i} = X_{b (i - 1)}

for i=1,2,…,⌊P/b⌋i = 1 , 2 , \dots , \lfloor P / b \rfloor. Values of b=100,000b = 100 , 000 were common in older generators, but values as large as b=1037b = 10^{37} are in use in modern combined linear congruential generators. (See, for instance, L’Ecuyer et al. [2002] for the implementation of such a generator.) Thus, a single random-number generator with k streams acts like k distinct virtual random-number generators, provided that the current value of seed for each stream is maintained. Exercise 21 illustrates one way to create streams that are widely separated in the random-number sequence.

There is the problem of comparing two or more alternative systems via simulation; there are advantages to dedicating portions of the pseudo-random number sequence to the same purpose in each of the simulated systems. For instance, in comparing the efficiency of several queueing systems, a fairer comparison will be achieved if all of the simulated systems experience exactly the same sequence of customer arrivals. Such synchronization can be achieved by assigning a specific stream to generate arrivals in each of the queueing simulations. If the starting seeds for these streams are

spaced far enough apart, then this has the same effect as having a distinct random-number generator whose only purpose is to generate customer arrivals.

4 Tests for Random Numbers

The desirable properties of random numbers—uniformity and independence—were discussed in Section 1. To check on whether these desirable properties have been achieved, a number of tests can be performed. (Fortunately, the appropriate tests have already been conducted for most commercia simulation software.) The tests can be placed in two categories, according to the properties of interest: uniformity and independence. A brief description of two types of tests is given in this section:

  1. Frequency test. Uses the Kolmogorov–Smirnov or the chi-square test to compare the distribution of the set of numbers generated to a uniform distribution.

  2. Autocorrelation test. Tests the correlation between numbers and compares the sample correlation to the desired correlation, zero

In testing for uniformity, the hypotheses are as follows:

H0 ⁣:Ri∼Uniform[0,1]H1 ⁣:Ri≁Uniform[0,1] \begin{array}{l l} H_{0} \colon & R_{i} \sim \text{Uniform[0,1]} \\ H_{1} \colon & R_{i} \not \sim \text{Uniform[0,1]} \end{array}

The null hypothesis,H0,H_{0} ,, reads that the numbers are distributed uniformly on the interval [0, 1]. Failure to reject the null hypothesis means that evidence of nonuniformity has not been detected by this test. This does not imply that further testing of the generator for uniformity is unnecessary.

In testing for independence, the hypotheses are as follows:

H0:Ri∼independentlyH1:Ri≁independently \begin{array}{l l} H_{0}: & R_{i} \sim \text{independently} \\ H_{1}: & R_{i} \not \sim \text{independently} \end{array}

This null hypothesis,H0,H_{0} ,, reads that the numbers are independent. Failure to reject the null hypothesis means that evidence of dependence has not been detected by this test. This does not imply that further testing of the generator for independence is unnecessary.

For each test, a level of significance α must be stated. The level α is the probability of rejecting the null hypothesis when the null hypothesis is true:

α=P(rejectH0∣H0true) \alpha = P (\text{reject} H_{0} | H_{0} \text{true})

The decision maker sets the value of α for any test. Frequently, α is set to 0.01 or 0.05.

If several tests are conducted on the same set of numbers, the probability of rejecting the nul hypothesis on at least one test, by chance alone (i.e., making a Type I (α) error), increases. Say that α=0.05\alpha = 0 . 05 and that five different tests are conducted on a sequence of numbers. The probability o rejecting the null hypothesis on at least one test, by chance alone, could be as large as 0.25.

Similarly, if one test is conducted on many sets of numbers from a generator, the probability of rejecting the null hypothesis on at least one test by chance alone (i.e., making a Type I (α) error), increases as more sets of numbers are tested. For instance, if 100 sets of numbers were subjected to the test, with α=0.05\alpha = 0 . 05, it would be expected that five of those tests would be rejected by chance alone. If the number of rejections in 100 tests is close to 100α, then there is no compelling reason to discard the generator. The concept discussed in this and the preceding paragraph is discussed further at the conclusion of Example 8.

If one of the well-known simulation languages or random-number generators is used, it is probably unnecessary to apply the tests just mentioned or those described in Sections 4.1 and 4.2. However, random-number generators frequently are added to software that is not specifically developed for simulation, such as spreadsheet programs, symbolic/numerical calculators, and programming languages. If the generator that is at hand is not explicitly known or documented, then the tests in this chapter should be applied to many samples of numbers from the generator. Some additiona tests that are commonly used, but are not covered here, are Good’s serial test for sampling numbers [1953, 1967], the median-spectrum test [Cox and Lewis, 1966; Durbin, 1967], the runs test [Law 2007], and a variance heterogeneity test [Cox and Lewis, 1966]. Even if a set of numbers passes al the tests, there is no guarantee of randomness; it is always possible that some underlying pattern has gone undetected.

In this text, we emphasize empirical tests that are applied to actual sequences of numbers produced by a generator. Because of the extremely long period of modern pseudo-random-number generators, as described in Section 3.2, it is no longer possible to apply these tests to a significan portion of the period of such generators. The tests can be used as a check if one encounters a generator with completely unknown properties (perhaps one that is undocumented and buried deep in a software package), but they cannot be used to establish the quality of a generator throughou its period. Fortunately, there are also families of theoretical tests that evaluate the choices for m, a, and c without actually generating any numbers, the most common being the spectral test. Many o these tests assess how k-tuples of random numbers fill up a k-dimensional unit cube. These tests are beyond the scope of this text; see, for instance, Ripley [1987].

In the examples of tests that follow, the hypotheses are not restated. The hypotheses are as indicated in the foregoing paragraphs. Although few simulation analysts will need to perform these tests, every simulation user should be aware of the qualities of a good random-number generator.

4.1 Frequency Tests

A basic test that should always be performed to validate a new generator is the test of uniformity. Two different methods of testing are the Kolmogorov–Smirnov and the chi-square test. Both of these tests measure the degree of agreement between the distribution of a sample of generated random numbers and the theoretical uniform distribution. Both tests are based on the null hypothesis of no significant difference between the sample distribution and the theoretical distribution.

  1. The Kolmogorov–Smirnov test. This test compares the continuous cdf F(x)F ( x ) of the uniform distribution with the empirical cdf SN(x)S_{N} ( x ) of the sample of N observations. By definition,
F(x)=x,0≤x≤1 F (x) = x, \quad 0 \leq x \leq 1

If the sample from the random-number generator is R1,R2,…,RNR_{1} , R_{2} , \ldots , R_{N}, then the empirical cdf SN(x)S_{N} ( x ) is defined by

SN(x)=number ofR1,R2,…,RNwhich are≤xN S_{N} (x) = \frac {\text{number of} R_{1} , R_{2} , \dots , R_{N} \text{which are} \leq x}{N}

As N becomes larger,SN(x)S_{N} ( x ) should become a better approximation to F(x)F ( x ), provided that the null hypothesis is true.

The cdf of an empirical distribution is a step function with jumps at each observed value.

The Kolmogorov–Smirnov test is based on the largest absolute deviation between F(x)F ( x ) and SN(x)S_{N} ( x ) over the range of the random variable—that is,{\mathrm{i s}} , it is based on the statistic

D=max⁡∣F(x)−SN(x)∣(3) D = \max | F (x) - S_{N} (x) |\tag{3}

The sampling distribution of D is known; it is tabulated as a function of N in Table A.8. For testing against a uniform cdf, the test procedure follows these steps:

Step 1. Rank the data from smallest to largest. Let R(i)R_{( i )} denote the ith smallest observation, so that

R(1)≤R(2)≤⋯≤R(N) R_{(1)} \leq R_{(2)} \leq \dots \leq R_{(N)}

Step 2. Compute

D+=max⁡1≤i≤N{iN−R(i)} D^{+} = \max_{1 \leq i \leq N} \left\{\frac {i}{N} - R_{(i)} \right\} D−=max⁡1≤i≤N{R(i)−i−1N} D^{-} = \max_{1 \leq i \leq N} \left\{R_{(i)} - \frac {i - 1}{N} \right\}

Step 3. Compute D=max⁡(D+,D−)D = \operatorname* {m a x} ( D^{+} , D^{-} ) Step 4. Locate the critical value DαD_{\alpha} in Table A.8 for the specified significance level α and the given sample size N.

Step 5. If the sample statistic D is greater than the critical value Dα.D_{\alpha} ., the null hypothesis that the data are a sample from a uniform distribution is rejected. I :D≤Dα: D \le D_{\alpha}, conclude that no difference has been detected between the true distribution of {R1,R2,…,RN}\{R_{1} , R_{2} , \ldots , R_{N} \} and the uniform distribution.

Example 6

Suppose that the five numbers 0.44, 0.81, 0.14, 0.05, 0.93 were generated, and it is desired to perform a test for uniformity by using the Kolmogorov–Smirnov test with the level of significance α=0.05\alpha = 0 . 05 First, the numbers must be sorted from smallest to largest. The calculations can be facilitated by use of Table 2. The top row lists the numbers from smallest (R(1))( R_{( 1 )} ) to largest (R(5))( R_{( 5 )} ). The computations for D+D^{+}, namely i/N−R(i)i / N - R_{( i )}, and for D−D^{-}, namely R(i)−(i−1)/NR_{( i )} - ( i - 1 ) / N, are easily accomplished by using Table 2. The statistics are computed as D+=0.26D^{+} = 0 . 26 and D−=0.21D^{-} = 0 . 21. Therefore,D=max⁡{0.26,0.21}=0.26D = \operatorname* {m a x} \{0 . 26 , 0 . 21 \} = 0 . 26 Table 2 Calculations for Kolmogorov–Smirnov Test

R(i)R_{(i)}0.050.140.440.810.93
i/Ni/N0.200.400.600.801.00
i/N−R(i)i/N - R_{(i)}0.150.260.16—0.07
R(i)−(i−1)/NR_{(i)} - (i-1)/N0.05—0.040.210.13

The critical value of D,D , obtained from Table A.8 in the Appendix for α=0.05\alpha = 0 . 05 and N=5,N = 5 ,, is 0.565. Since the computed value, 0.26, is less than the tabulated critical value, 0.565, the hypothesis tha the distribution of the generated numbers is the uniform distribution is not rejected.

The calculations in Table 2 are illustrated in Figure 2, where the empirical cdf SN(x)S_{N} ( x ) is compared to the uniform cdf F(x)F ( x ). It can be seen that D+D^{+} is the largest deviation of SN(x)S_{N} ( x ) above F(x)F ( x )), and that D−D^{-} is the largest deviation of SN(x)S_{N} ( x ) below F(x)F ( x ). For example, at R(3)R_{( 3 )}, the value of D+D^{+} is given by 3/5−R(3)=0.60−0.44=0.16.3 / 5 - R_{( 3 )} = 0 . 60 - 0 . 44 = 0 . 16 {\mathrm{.}}, and that of D−D^{-} is given by R(3)−2/5=0.44−0.40=0.04R_{( 3 )} - 2 / 5 = 0 . 44 - 0 . 40 = 0 . 04 Although the test statistic D is defined by Equation (3) as the maximum deviation over all x, it can be seen from Figure 2 that the maximum deviation will always occur at one of the jump points R(1),R(2),…,R(N);R_{( 1 )} , R_{( 2 )} , \ldots , R_{( N )} ;; thus, the deviation at other values of x need not be considered.

  1. The chi-square test. The chi-square test uses the sample statistic
χ02=∑i=1n(Oi−Ei)2Ei \chi_{0} ^ {2} = \sum_{i = 1} ^ {n} \frac {(O_{i} - E_{i}) ^ {2}}{E_{i}}

where OiO_{i} is the observed number in the ith class,EiE_{i} is the expected number in the ith class, and n is the number of classes. For the uniform distribution Ei,E_{i} ,, the expected number in each class is given by

Ei=Nn E_{i} = \frac {N}{n}

for equally spaced classes, where N is the total number of observations. It can be shown that the sampling distribution of χ02\chi_{0} ^ {2} is approximately the chi-square distribution with n 1 degrees offreedom.

Example 7

Use the chi-square test with α=0.05\alpha = 0 . 05 to test for whether the data shown next are uniformly distributed. Table 3 contains the essential computations. The test uses n=10n = 10 intervals of equal length, namely [0,0.1),[0.1,0.2),…,[0.9,1.0)[ 0 , 0 . 1 ) , [ 0 . 1 , 0 . 2 ) , \ldots , [ 0 . 9 , 1 . 0 ). The value of χ02\chi_{0} ^ {2} is 3.4. This is compared with the critical value χ0.05,92=16.9\chi_{0 . 05 , 9} ^ {2} = 16 . 9 from Table A.6. Since χ02\chi_{0} ^ {2} is much smaller than the tabulated value of χ0.05,92\chi_{0 . 05 , 9} ^ {2}, the null hypothesis of a uniform distribution is not rejected.

Figure 2 Comparison of F(x) and SN(x)S_{N} ( x )| 0.34 | 0.90 | 0.25 | 0.89 | 0.87 | 0.44 | 0.12 | 0.21 | 0.46 | 0.67 |

0.830.760.790.640.700.810.940.740.220.74
0.960.990.770.670.560.410.520.730.990.02
0.470.300.170.820.560.050.450.310.780.05
0.790.710.230.190.820.930.650.370.390.42
0.990.170.990.460.050.660.100.420.180.49
0.370.510.540.010.810.280.690.340.750.49
0.720.430.560.970.300.940.960.580.730.05
0.060.390.840.240.400.640.400.190.790.62
0.180.260.970.880.640.470.600.110.290.78

Different authors have offered considerations concerning the application of the chi-square test. In the application to a data set the size of that in Example 7, the considerations do not apply—that is, if 100 values are in the sample and from 5 to 10 intervals of equal length are used, the test will be acceptable. In general, it is recommended that n and N be chosen so that each Ei≥5E_{i} \geq 5 Both the Kolmogorov–Smirnov test and the chi-square test are acceptable for testing the uniformity of a sample of data, provided that the sample size is large. However, the Kolmogorov–Smirnov test is the more powerful of the two and is recommended. Furthermore, the Kolmogorov–Smirnov test can be applied to small sample sizes, whereas the chi-square is valid only for large samples, say N≥50N \geq 50 Table 3 Computations for Chi-Square Test

IntervalOiO_iEiE_iOi−EiO_i - E_i(Oi−Ei)2(O_i - E_i)^2(Oi−Ei)2Ei\frac{(O_i - E_i)^2}{E_i}
1810-240.4
2810-240.4
31010000.0
4910-110.1
51210240.4
6810-240.4
71010000.0
814104161.6
91010000.0
101110110.1
10010003.4

Imagine a set of 100 numbers that are being tested for independence, one where the first 10 values are in the range 0.01–0.10, the second 10 values are in the range 0.11–0.20, and so on. This set of numbers would pass the frequency tests with ease, but the ordering of the numbers produced by the generator would not be random. The test in the next section of this chapter is concerned with the independence of random numbers that are generated.

4.2 Tests for Autocorrelation

The tests for autocorrelation are concerned with the dependence between numbers in a sequence. As an example, consider the following sequence of numbers, read from left to right:

0.120.010.230.280.890.310.640.280.830.93
0.990.150.330.350.910.410.600.270.750.88
0.680.490.050.430.950.580.190.360.690.87

From a visual inspection, these numbers appear random, and they would probably pass all the tests presented to this point. However, an examination of the 5th, 10th, 15th (every five numbers beginning with the fifth), and so on, indicates a very large number in that position. Now, 30 numbers is a rather small sample size on which to reject a random number generator, but the notion is that numbers in the sequence might be related. In this particular section, a method for discovering whether such a relationship exists is described. The relationship would not have to be all high numbers. It is possible to have all low numbers in the locations being examined, or the numbers could alternate from very high to very low.

The test to be described shortly requires the computation of the autocorrelation between every  numbers ( is also known as the lag),l a g ) ,, starting with the ith number. Thus, the autocorrelation ρiℓ\rho_{i \ell} between the following numbers would be of interest:Ri,Ri+ℓ,Ri+2ℓ,…,Ri+(M+1)ℓR_{i} , R_{i + \ell} , R_{i + 2 \ell} , \ldots , R_{i + ( M + 1 ) \ell}. The value M is the largest integer such that i+(M+1)ℓ≤Ni + ( M + 1 ) \ell \leq N, where N is the total number of values in the sequence. (Thus, a subsequence of length M+2M + 2 is being tested.)

Figure 3 Failure to reject hypothesis.

A nonzero autocorrelation implies a lack of independence, so the following two-tailed test is appropriate:

H0:ρiℓ=0H1:ρiℓ≠0 \begin{array}{r l} {H_{0}:} & {\rho_{i \ell} = 0} \\ {H_{1}:} & {\rho_{i \ell} \neq 0} \end{array}

For large values of M, the distribution of the estimator of ρiℓ\rho_{i \ell}, denoted ρ^iℓ\widehat {\rho} _ {i \ell}, is approximately normal if the values Ri,Ri+ℓ,Ri+2ℓ,…,Ri+(M+1)ℓR_{i} , R_{i + \ell} , R_{i + 2 \ell} , \ldots , R_{i + ( M + 1 ) \ell} are uncorrelated. Then the test statistic can be formed as follows:

Z0=ρ^iℓσρ^iℓ Z_{0} = \frac {\widehat {\rho} _ {i \ell}}{\sigma_ {\widehat {\rho} _ {i \ell}}}

which is distributed normally with a mean of zero and a variance of 1, under the assumption of independence, for large M.

The formula for ρ^iℓ\widehat {\rho} _ {i \ell}, in a slightly different form, and the standard deviation of the estimator σρ^iℓ\sigma _ {\hat {\rho} _ {i \ell}} are given by Schmidt and Taylor [1970] as follows:

ρ^iℓ=1M+1[∑k=0MRi+kℓRi+(k+1)ℓ]−0.25 \widehat {\rho} _ {i \ell} = \frac {1}{M + 1} \left[ \sum_{k = 0} ^ {M} R_{i + k \ell} R_{i + (k + 1) \ell} \right] - 0. 25

and

σρ^iℓ=13M+712(M+1) \sigma_ {\hat {\rho} _ {i \ell}} = \frac {\sqrt {13 M + 7}}{12 (M + 1)}

After computing Z0,Z_{0} , do not reject the null hypothesis of independence if−zα/2≤Z0≤zα/2\mathrm{i f} - z_{\alpha / 2} \le Z_{0} \le z_{\alpha / 2} where α is the level of significance and zα/2z_{\alpha / 2} is obtained from Table A.3. Figure 3 illustrates this test.

If ρiℓ>0.\rho_{i \ell} > 0 ., the subsequence is said to exhibit positive autocorrelation. In this case, successive values at lag  have a higher probability than expected of being close in value (i.e.( \mathrm{i . e .}, high random numbers in the subsequence followed by high, and low followed by low). On the other hand, if ρiℓ<0\rho_{i \ell} < 0 the subsequence is exhibiting negative autocorrelation, which means that low random numbers tend

to be followed by high ones, and vice versa. The desired property, independence (which implies zero autocorrelation), means that there is no discernible relationship of the nature discussed here between successive random numbers at lag .

Example 8

Test for whether the 3rd, 8th, 13th, and so on, numbers in the sequence at the beginning of this section are autocorrelated using α=0.05\alpha = 0 . 05. Here, i 3 (beginning with the third number),ℓ=5\ell = 5(every five numbers),N=30N = 30(30 numbers in the sequence), and M=4M = 4(largest integer such tha 3+(M+1)5≤30)3 + ( M + 1 ) 5 \le 30 ). Then,

ρ^35=14+1[(0.23)(0.28)+(0.28)(0.33)+(0.33)(0.27)+(0.27)(0.05)+(0.05)(0.36)]−0.25=−0.1945 \begin{array}{r l} \widehat {\rho} _ {35} & = \frac {1}{4 + 1} [ (0. 23) (0. 28) + (0. 28) (0. 33) + (0. 33) (0. 27) + (0. 27) (0. 05) \\ & \quad + (0. 05) (0. 36) ] - 0. 25 \\ & = - 0. 1945 \end{array}

and

σρ^35=13(4)+712(4+1)=0.1280 \sigma_ {\hat {\rho} _ {35}} = \frac {\sqrt {13 (4) + 7}}{12 (4 + 1)} = 0. 1280

Then, the test statistic assumes the value

Z0=−0.19450.1280=−1.516 Z_{0} = - \frac {0 . 1945}{0 . 1280} = - 1. 516

Now, the critical value from Table A.3 is

z0.025=1.96 z_{0. 025} = 1. 96

Therefore, the hypothesis of independence cannot be rejected on the basis of this test.

It can be observed that this test is not very sensitive for small values of M, particularly when the numbers being tested are on the low side. Imagine what would happen if each of the entries in the foregoing computation of ρ^iℓ\widehat {\rho} _ {i \ell} were equal to zero. Then ρ^iℓ\widehat {\rho} _ {i \ell} would be equal to 0.25 and the calculated Z would have the value of 1.95, not quite enough to reject the hypothesis of independence.

There are many sequences that can be formed in a set of data, given a large value of N. For example, beginning with the first number in the sequence, possibilities include (a) the sequence of all numbers, (b) the sequence formed from the first, third, fifth, . . . , numbers, (c) the sequence formed from the first, fourth, . . . , numbers, and so on. If α=0.05\alpha = 0 . 05, there is a probability of 0.05 of rejecting a true hypothesis. If 10 independent sequences are examined, the probability of finding no significan autocorrelation, by chance alone, is (0.95)10( 0 . 95 ) ^ {10} or 0.60. Thus, 40% of the time significant autocorrelation would be detected when it does not exist. If α is 0.10 and 10 tests are conducted, there is a 65% chance of finding autocorrelation by chance alone. In conclusion, in “fishing” for autocorrelation by performing numerous tests, autocorrelation might eventually be detected, perhaps by chance alone, even when there is no autocorrelation present.

5 Summary

This chapter described the generation of random numbers and the subsequent testing of the generated numbers for uniformity and independence. Random numbers are used to generate random variates.

Of the many types of random-number generators available, ones based on the linear congruentia method are the most widely used, but they are being replaced by combined linear congruentia generators. Of the many types of statistical tests that are used in testing random-number generators, two different types are described: one testing for uniformity and one testing for independence.

The simulation analyst might never work directly with a random-number generator or with the testing of random numbers from a generator. Most computers and simulation languages have methods that generate a random number, or streams of random numbers, for the asking. But even generators that have been used for years, some of which are still in use, have been found to be inadequate. So this chapter calls the simulation analyst’s attention to such possibilities, with a warning to investigate and confirm that the generator has been tested thoroughly. Some researchers have attained sophisticated expertise in developing methods for generating and testing random numbers and the subsequent application of these methods. This chapter provides only a basic introduction to the subject matter; more depth and breadth are required for the reader to become a specialist in the area. An importan foundational reference is Knuth [1998]; see also the reviews in Bratley, Fox, and Schrage [1996], Law [2007], L’Ecuyer [1998], and Ripley [1987].

One final caution is due. Even if generated numbers pass all the tests (those covered in this chapter and those mentioned in the chapter), some underlying pattern might have gone undetected without the generator’s having been rejected as faulty. However, the generators available in widely used simulation languages have been extensively tested and validated.

REFERENCES

BRATLEY, P., B. L. FOX, AND L. E. SCHRAGE [1996], A Guide to Simulation, 2d ed., Springer-Verlag, New York.

COX, D. R., AND P. A. W. LEWIS [1966], The Statistical Analysis ofSeries ofEvents, Methuen, London.

DURBIN, J. [1967], “Tests of Serial Independence Based on the Cumulated Periodogram,” Bulletin of the International Institute ofStatistics, vol. 42, pp. 1039–1049.

GOOD, I. J. [1953], “The Serial Test for Sampling Numbers and Other Tests of Randomness,” Proceedings of the Cambridge Philosophical Society, Vol. 49, pp. 276–284.

GOOD, I. J. [1967], “The Generalized Serial Test and the Binary Expansion of 4,” Journal ofthe Royal Statistical Society, Ser. A, Vol. 30, No. 1, pp. 102–107.

KNUTH, D. W. [1998], TheArt ofComputer Programming:Vol. 2, Semi-numericalAlgorithms, 2d ed.,Addison– Wesley, Reading, MA.

LAW, A. M. [2007], Simulation Modeling and Analysis, 4th ed., McGraw-Hill, New York.

LEARMONTH, G. P., AND P. A. W. LEWIS [1973], “Statistical Tests of Some Widely Used and Recently Proposed Uniform Random Number Generators,” Proceedings ofthe Conference on Computer Science and Statistics: Seventh Annual Symposium on the Interface, Western Publishing, North Hollywood, CA, pp. 163–171.

L’ECUYER, P. [1988], “Efficient and Portable Combined Random Number Generators,” Communications of the ACM, Vol. 31, pp. 742–749, 774.

L’ECUYER, P. [1996], “Combined Multiple Recursive Random Number Generators,” Operations Research, Vol. 44, pp. 816–822.

L’ECUYER, P. [1998], “Random Number Generation,” Chapter 4 in Handbook of Simulation, J. Banks, ed., pp. 93–137. Wiley, New York.

L’ECUYER, P. [1999], “Good Parameters and Implementations for Combined Multiple Recursive Random Number Generators,” Operations Research, Vol. 47, pp. 159–164.

L’ECUYER, P., R. SIMARD, E. J. CHEN,AND W. D. KELTON [2002], “An Object-Oriented Random-Number Package with Many Long Streams and Substreams,” Operations Research, Vol. 50, pp. 1073–1075.

LEHMER, D. H. [1951], “Mathematical Methods in large-Scale Computing Units,” Proceedings ofthe Second Symposium on Large-Scale Digital Calculating Machinery, Harvard University Press, Cambridge, MA, pp. 141–146.

LEWIS, P. A. W., A. S. GOODMAN, AND J. M. MILLER [1969], “A Pseudo-Random Number Generator for the System/360,” IBM Systems Journal, Vol. 8, pp. 136–145.

RIPLEY, B. D. [1987], Stochastic Simulation, Wiley, New York.

SCHMIDT, J. W., and R. E. TAYLOR [1970], Simulation and Analysis of Industrial Systems, Irwin, Home wood, IL.

EXERCISES

  1. Describe a procedure to physically generate random numbers on the interval [0, 1] with 2-digit accuracy. [Hint: Consider drawing something out of a hat.]

  2. List applications, other than systems simulation, for pseudo-random numbers—for example, video gambling games.

  3. How could random numbers that are uniform on the interval [0, 1] be transformed into random numbers that are uniform on the interval [ 11, 17]?

  4. Use the linear congruential method to generate a sequence of three two-digit random integers and corresponding random numbers. Let X 27, a 8, c 47, and m 100.

  5. Do we encounter a problem in the previous exercise if X0=0?X_{0} = 0 ?6. Use the multiplicative congruential method to generate a sequence of four three-digit random integers and corresponding random numbers. Let X0=117X_{0} = 117, a 43, and m 1000.

  6. The sequence ofnumbers 0.54, 0.73, 0.98, 0.11, and 0.68 has been generated. Use the Kolmogorov– Smirnov test with α=0.05\alpha = 0 . 05 to learn whether the hypothesis that the numbers are uniformly distributed on the interval [0, 1] can be rejected.

  7. Reverse the 100 two-digit random numbers in Example 7 to get a new set of random numbers. Thus, the first random number in the new set will be 0.43. Use the chi-square test, with α=0.05\alpha = 0 . 05 to learn whether the hypothesis that the numbers are uniformly distributed on the interval [0, 1] can be rejected.

  8. Figure out whether these linear congruential generators can achieve a maximum period; also, state restrictions on X0X_{0} to obtain this period:

(a) the mixed congruential method with

a=2,814,749,767,109c=59,482,661,568,307m=248 \begin{array}{l} a = 2, 814, 749, 767, 109 \\ c = 59, 482, 661, 568, 307 \\ m = 2^{48} \end{array}

(b) the multiplicative congruential generator with

a=69,069c=0m=232 \begin{array}{l} {a = 69, 069} \\ {c = 0} \\ {m = 2^{32}} \end{array}

(c) the mixed congruential generator with

a=4951c=247m=256 \begin{array}{c} {a = 4951} \\ {c = 247} \\ {m = 256} \end{array}

(d) the multiplicative congruential generator with

a=6507c=0m=1024 \begin{array}{c} {a = 6507} \\ {c = 0} \\ {m = 1024} \end{array}
  1. Use the mixed congruential method to generate a sequence of three two-digit random integers and corresponding random numbers with X0=37,a=7,c=29X_{0} = 37 , a = 7 , c = 29, and m=100m = 10011. Use the mixed congruential method to generate a sequence of three two-digit random integers between 0 and 24 and corresponding random numbers with X0=13,a=9X_{0} = 13 , a = 9, and c=35c = 3512. Write a computer program that will generate four-digit random numbers, using the multiplicative congruential method. Allow the user to input values of X0,a,c.X_{0} , a , c ., and m.m .13. If X0=3579X_{0} = 3579 in Exercise 9(c).9 ( \mathrm{c} ) ., generate the first random number in the sequence. Compute the random number to four-place accuracy.

  2. Investigate the random-number generator in a spreadsheet program on a computer to which you have access. In many spreadsheets, random numbers are generated by a function called RAND or @RAND.

(a) Check the user’s manual to see whether it describes how the random numbers are generated.

(b) Write macros to conduct each of the tests described in this chapter. Generate 100 sets o random numbers, each set containing 1000 random numbers. Perform each test on each set of random numbers. Draw conclusions.

  1. Consider the multiplicative congruential generator under the following circumstances:

(a) X0=7,a=11,m=16X_{0} = 7 , a = 11 , m = 16(b) X0=8,a=11,m=16X_{0} = 8 , a = 11 , m = 16(c) X0=7,a=7,m=16X_{0} = 7 , a = 7 , m = 16

(d)X0=8,a=7,m=16 \mathrm{(d)} X_{0} = 8, a = 7, m = 16

Generate enough values in each case to complete a cycle. What inferences can be drawn? Is maximum period achieved?

  1. L’Ecuyer [1988] provides a generator that combines three multiplicative generators, with a1=a_{1} =157,m1=32,363,a2=146,m2=31,727,a3=142m_{1} = 32 , 363 , a_{2} = 146 , m_{2} = 31 , 727 , a_{3} = 142, and m3=31,657m_{3} = 31 , 657. The period of this generator is approximately 8×10128 \times 10^{12}. Generate 5 random numbers with the combined generator, using the initial seeds X1,0=100,X2,0=300X_{1 , 0} = 100 , X_{2 , 0} = 300 and X3,0=500X_{3 , 0} = 500, for the individual generators.

  2. Apply the tests described in this chapter to the generator given in the previous exercise.

  3. Use the principles described in this chapter to develop your own linear congruential randomnumber generator.

  4. Use the principles described in this chapter to develop your own combined linear congruentia random-number generator.

  5. Test the following sequence of numbers for uniformity and independence, using procedures you learned in this chapter: 0.594, 0.928, 0.515, 0.055, 0.507, 0.351, 0.262, 0.797, 0.788, 0.442, 0.097, 0.798, 0.227, 0.127, 0.474, 0.825, 0.007, 0.182, 0.929, 0.852.

  6. In some applications, it is useful to be able to quickly skip ahead in a pseudo-random number sequence without actually generating all of the intermediate values.

(a) For a linear congruential generator with c=0.c = 0 ., show that Xi+n=(anXi)X_{i + n} = ( a^{n} X_{i} ) mod m.m ..

(b) Next, show that (anXi)( a^{n} X_{i} ) mod m=(anm = ( a^{n} mod m)Xim ) X_{i} mod m (this result is useful because ana^{n} mod m can be precomputed, making it easy to skip ahead n random numbers from any point in the sequence).

(c) In Example 3, use this result to compute X5,X_{5} ,, starting with X0=63X_{0} = 63. Check your answer by computing X5X_{5} in the usual way.

  1. Producing good pseudo-random-number generators is much more difficult than it seems. For instance, mathematical genius John Von Neumann proposed the middle-square method. To generate, say, six-digit pseudo-random numbers by the middle-square method, begin with a six-digit integer as the seed. Square the number and extract the middle six digits as the next number in the sequence. Continue the process by repeatedly squaring the current number and extracting the middle six digits as the next number. To obtain numbers between 0 and 1, a decimal point can be placed in front of the six digits. Try a few examples to show how this method can fail spectacularly. (Von Neumann was aware of these problems.)

List of Materials Available on www.bcnn.net

RandomNumberTools.xls