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

Random Number Generators

1
Outline

• Random Numbers
• Why To Prefer Pseudo- Random Numbers
• Application Areas
• The Linear Congruential Generators
• Period of Linear Congruential Sequence
• Approaches to the Generation of Random
Numbers on Parallel Computers
• Centralized
• Replicated
• Distributed
Outline

• Some Tests For Random Number Generators


• Testing Parallel Random Number Generators
• SPRNG (Scalable Library for Pseudorandom Number
Generation)
Random Number Generators

•Random number generation is a method of


producing a sequence of numbers that lack any
discernible pattern.

•Random Number Generators (RNGs) have


applications in a wide range of different fields and
are used heavily in computational simulations.

4
What is Random?

•What do we mean by Random?


• Uncorrelated (with what you're interested in)
• Quantum systems are truly random (we
believe)
• Some times we want repeatability from a random
number generator.

5
Pseudo RNGs

•With the exception of some specially made add-on


cards, computer generated random numbers are
obviously not truly random.

•Computational RNGs are referred to as Pseudo


Random Number Generators, meaning they are
random enough.

6
Pseudo RNGs

•PRNGs usually generate very long sequences of


random numbers. For example the commonly used
Mersenne Twister MT19937 has a sequence length
of 219937-1.

•Basically a sequence that will not recur in any


practice compute time – eg the lifetime of the known
universe.

7
Pseudo RNGs

•While long sequence length is a good property of a


PRNG, it is not sufficient to ensure that the numbers
generated are random.

•We can define a number of properties that random


numbers should have and use them to test PRNGs.

8
Random Numbers

• Well-known sequential techniques exist for


generating, in a deterministic fashion,
• The number sequences are largely
indistinguishable from true random sequences
• The deterministic nature is important because it
provides for reproducibility in computations.
• Efficiency is needed by preserving randomness and
reproducibility
Random Numbers

• Consider the following experiment to verify the


randomness of an infinite sequence of integers in
[1,d].
• Suppose we let you view as many numbers from the
sequence as you wished to.
• You should then guess any other number in the
sequence.
• If the likelihood of your guess being correct is greater
than 1/d, then the sequence is not random.
• In practice, to estimate the winning probabilities we
must play this guessing game several times.
Why To Prefer Pseudo- Random Numbers

• True random numbers are rarely used in


computing because:
• difficult to generate reliably
• the lack of reproducibility would make the validation of
programs that use them extremely difficult
• Computers use pseudo-random numbers:
• finite sequences generated by a deterministic process
• but indistinguishable, by some set of statistical tests,
from a random sequence.
Application Areas
• Simulation: When we simulate natural
phenomena, random numbers are required to
make things realistic. For example: Operations
research (where people come into airport at
random intervals.)
• Sampling: It is often impractical to examine all
possible cases, but a random sample will provide
insight into what constitutes "typical" behaviour.
• Computer Programming: Random values make
good source of data for testing the effectiveness
of computer algorithms.
Application Areas

• Numerical Analysis
• Decision Making: There are reports that many
executives make their decisions by flipping a coin
or by throwing darts, etc.
• Aesthetics: A little bit randomness makes
computer-generated graphics and music seem
more lively.
• Recreation: "Monte Carlo method", a general term
used to describe any algorithm that employs
random numbers.
Generator Algorithms

•Computer systems often come supplied with a RNG


built in.

•eg rand() or random()

•While these are fast and easy to use, they may not
be very random, have short repeat sequences and
may have strong correlation patterns.

14
The Linear Congruential Generators

• Generator is a function, when applied to a


number, yields the next number in the sequence.
For example,
• X_k+1 = (a * X_k + c) mod m
where X_k is the k th element of the sequence and
X_0, a, c , and m define the generator.
• As numbers are taken from a finite set (for
example, integers between 1 and 2^31), any
generator will eventually repeat itself.
Linear Congruential Generator

•Many built-in RNGs use the Linear Congruential


Generator or LCG. This generator is very fast, has low
memory requirements but for most serious
applications where randomness actually matters, it is
useless.

16
Linear Congruential Generator

• A sequence of random values Xn where:


Xn+1 = ( a Xn + c ) mod m
• with well-chosen values of a, c, m

• Period is at most m (and can be shorter for “bad”


choices..)

17
Linear Congruential Generator

• Example Sequences:
m=10, a=2, c=1 m=10, a=1, c=7

1 1
3 (2*1 + 1 % 10) 8 (1*1 + 7 % 10)
7 (2*3 + 1 % 10) 5 (1*8 + 7 % 10)
5 (2*7 + 1 % 10) 2 (1*5 + 7 % 10)
1 (2*5 + 1 % 10) 9 (1*2 + 7 % 10)
3 (2*1 + 1 % 10) 6 (1*9 + 7 % 10)
7 (2*3 + 1 % 10) 3 (1*6 + 7 % 10)
5 (2*7 + 1 % 10) 0 (1*3 + 7 % 10)
… …

18
Linear Congruential Generator

• Various sources use different parameters for the


LCG:

• Numerical Recipes
• m = 232 a = 1664525 c = 1013904223
• GCC
• m = 232 a = 1103515245 c = 12345
• MMIX
• m = 264 a = 6364136223846793005 c = 1442695040888963407

19
Lagged Fibonacci Generator

• The Lagged Fibonacci Generator is based on a


generalisation of the Fibonacci sequence

• 1, 1, 2, 3, 5, 8, 13, 21 ....

• Obtained from the sequence

• Xn = Xn-1 + Xn-2

20
Lagged Fibonacci Generator

• The LFG generator is defined by:

• Xn = (Xn-j OP Xn-k) mod m


• Where:
• OP is some binary operator +, -, *, /, XOR.
•0 < j < k

• This algorithm produces a higher quality of random


numbers but requires the storage of k past states.

21
The Linear Congruential Generators

• The length of the repeated cycle is called the period of the


generator.
• A good generator is one with a long period and no discernible
correlation between elements of the sequence.
• Example: X_k+1 = (3 * X_k + 4) mod 8
E = {1, 7, 1, 7, …} is bad.
Period of Linear Congruential Sequence

• Theorem: The linear congruential sequence has period m if and only


if
• c is relatively prime to m;
• b = a - 1 is a multiple of p, for every prime p dividing m;
• b is a multiple of 4, if m is a multiple of 4.
• Example: X_k+1 = (7 * X_k + 5) mod 18
E = {1, 12, 17, 16, 9, 14, 13, 6, 11, 10, 3, 8, 7, 0, 5, 4, 15, 2, 1,…}
Approaches to the Generation of Random
Numbers on Parallel Computers

• Centralized
• Replicated
• Distributed
Centralized Approach
• A sequential generator is encapsulated in a task
from which other tasks request random numbers.
• Advantages:
• Avoids the problem of generating multiple
independent random sequences
• Disadvantages:
• Unlikely to provide good performance
• Makes reproducibility hard to achieve: the response to
a request depends on when it arrives at the generator,
and the result computed by a program can vary from
one run to the next.
Replicated Approach

• Multiple instances of the same generator are


created (for example, one per task). Each
generator uses either the same seed or a unique
seed, derived, for example, from a task identifier.
• Advantages:
• Efficiency
• Ease of implementation
• Disadvantages:
• Not guaranteed to be independent and, can suffer from
serious correlation problems.
Distributed Approach

• Responsibility for generating a single sequence is


partitioned among many generators, which can
then be parcelled out to different tasks.
• Advantages:
• The analysis of the statistical properties of the
distributed generator is simplified because the
generators are all derived from a single generator
• Efficiency
• Disadvantages:
• Difficult to implement on parallel computers
Distributed Approaches

• The techniques described here are based on an


adaptation of the linear congruential algorithm
called the random tree method.
• This facility is particularly valuable in
computations that create and destroy tasks
dynamically during program execution.
♦ The Random Tree Method
♦ The Leapfrog Method
♦ Modified Leapfrog
The Random Tree Method
• The random tree method employs two linear congruential
generators, L and R , that differ only in the values used for a .
• L_k+1 = a_L L_k mod m
• R_k+1 = a_R R_k mod m

R0
R1
R2
• Application of the left generator L to a seed
generates one random sequence; application of
the right generator R to the same seed
generates a different sequence.
• By applying the right generator to elements of
the left generator's sequence (or vice versa), a
tree of random numbers can be generated.
• By convention, the right generator R is used to
generate random values for use in computation,
while the left generator L is applied to values
computed by R to obtain the starting points R0,
R1 , etc., for new right sequences.
Random Tree Method

• Advantages:
• Useful to generate new random sequences in a
reproducible and noncentralized fashion. This is
valuable, in applications in which new tasks and hence
new random generators must be created dynamically.
• Disadvantages:
• There is no guarantee that different right sequences will
not overlap. If two starting points happen to be close to
each other, the two right sequences that are generated
will be highly correlated.
The Leapfrog Method
• A variant of the random tree method
• Used to generate sequences that can be guaranteed not to overlap
for a certain period.
• Useful where a program requires a fixed number of generators. (For
example, one generator for each task ).
R0 R1 R2

L_0

L_1

L_2
L_3
L_4

L_5
L_6
L_7
L_8

Figure: The leapfrog method with n=3. Each of the right generators selects a
disjoint subsequence of the sequence constructed by the left generator’s
sequence.
• Let n be the number of sequences required. Then we
define a_L and a_R as a and a^n, respectively,
• L_k+1 = a L_k mod m
• R_k+1 = a^n R_k mod m
• Create n different right generators R0 .. Rn-1 by taking the
first n elements of L as their starting values.
• The name “leapfrog method” refers that the i th sequence
Ri consists of L_i and every n th subsequent element of
the sequence generated by L.
• As the method partitions the elements of L, each
subsequence has a period of at least P/n, where P is the
period of L.
• The n subsequences are disjoint for their first P/n
elements.
• The generator for the r th subsequence, Rr , is defined by
a^n and Rr_0 = L_r.
• First, compute a^r and a^n
• Then, compute members of the sequence Rr as follows, to
obtain n generators, each defined by a triple (Rr_0, a^n,
m) , for
0 <= r < n .
• Rr_0 = (a^r L_0) mod m
• Rr_i+1 = (a^n Rr_I) mod m
Modified Leapfrog

• A variant of the leapfrog method


• Used in situations, where we know the maximum number,
n , of random values needed in a subsequence but not the
number of subsequences required.
• The role of L and R are reversed so that the elements of
subsequence i are the contiguous elements
• L_k+1 = a^n L_k mod m
• R_k+1 = a R_k mod m
• It is not a good idea to choose n as a power of two, as this
can lead to serious long-term correlations.
R0 R1 R2 …
L_0

L_1

L_2
L_3
L_4

L_5
L_6
L_7
L_8

Figure: Modified leapfrog with n=3 . Each subsequence contains three


contiguous numbers from the main sequence.
Some Tests For Random Number Generators

• The basic idea behind the statistical tests is that the


rabdom number streams obtained from a generator should
have the properties of a random sample drawn from the
uniform distribution.
• Tests are designed so that the expected value of some test
statistic is known for uniform distribution.
• The empirically generated random number stream is then
subject to the same test, and the statistic obtained is
compared against the expected value.
Frequency Test
• The focus of the test is the proportion of zeroes
and ones for the entire sequence.
• Example:
• (input)
E=1100100100001111110110101010001000100001011
010001100001000110100110001001100011001100010
100010111000
• (input) n = 100
• (output) P-value = 0.109599
• (conclusion) Since P-value >= 0.01, accept the sequence
as random.
Runs Test
• A run is an uninterrupted sequence of identical
bits.
• The focus of this test is the total number of runs in
the sequence.
• A run of length k consists of exactly k identical bits
and is bounded before and after with a bit of the
opposite value.
• The purpose of the runs test is to determine
whether the number of runs of ones and zeros of
various lengths is as expected for a random
sequence.
• Determines whether the oscillation between such
zeros and ones is too fast or too slow.
Runs Test
• A fast oscillation occurs when there are a lot of
changes, e.g., 010101010 oscillates with every bit.
• (input) E =
11001001000011111101101010100010001000010
11010001100001000110100110001001100011001
100010100010111000
• (input) n = 100
• (output) P-value = 0.500798
• (conclusion) Since P-value >= 0.01, accept the
sequence as random.
Random Number Generation

Desirable Attributes:
•Uniformity
•Independence
•Efficiency
•Replicability
•Long Cycle Length

42
Random Number Generation (cont.)

Each random number Rt is an independent sample


drawn from a continuous uniform distribution
between 0 and 1
1 , 0 ≤ x ≤ 1
pdf: f(x) = 
0 , otherwise

43
Random Number Generation
(cont.)
1

PDF:

f(x)
0 x
1
E ( R ) = ∫ xdx = [ x 2 / 2]10 = 1 / 2
0
1
V ( R ) = ∫ x 2 dx − [ E ( R )]2
0

= [ x 3 / 3] − (1 / 2) 2 = 1 / 3 − 1 / 4
1
0
= 1 / 12

44
Techniques for Generating Random Number

MidSquare
Example:
X0 = 7182 (seed)
X 02 = 51581124
==> R1 = 0.5811
X 02 = (5811) 2 = 33767721
==> R2 = 0.7677
etc.

45
Techniques for Generating Random Number
(cont.)
Note: Cannot choose a seed that guarantees that the
sequence will not degenerate and will have a long
period. Also, zeros, once they appear, are carried in
subsequent numbers.
Ex1: X0 = 5197 (seed) = 27008809
==> R1 = 0.0088 X 02= 00007744
==> R2 = 0.0077 X12
Ex2: X0 = 4500 (seed) = 20250000
==> R1 = 0.2500 X 02= 06250000
==> R2 = 0.2500 X1 2

46
Techniques for Generating Random Number
(cont.)
Multiplicative Congruential Method:
Basic Relationship
Xi+1 = a Xi (mod m), where a ≥ 0 and m ≥ 0
Most natural choice for m is one that equals to
the capacity of a computer word.
m = 2b (binary machine), where b is the number
of bits in the computer word.
m = 10d (decimal machine), where d is the
number of digits in the computer word.

47
Techniques for Generating Random Number
(cont.)
The max period(P) is:
For m a power of 2, say m = 2b, and c ≠ 0, the longest
possible period is P = m = 2b , which is achieved provided
that c is relatively prime to m (that is, the greatest
common factor of c and m is 1), and a = 1 + 4k, where k is
an integer.
For m a power of 2, say m = 2b, and c = 0, the longest
possible period is P = m / 4 = 2b-2 , which is achieved
provided that the seed X0 is odd and the multiplier, a, is
given by a = 3 + 8k or a = 5 + 8k, for some k = 0, 1,...

48
Techniques for Generating Random Number
(cont.)

For m a prime number and c = 0, the


longest possible period is P = m - 1, which
is achieved provided that the multiplier, a,
has the property that the smallest integer
k such that ak - 1 is divisible by m is k = m -
1,

49
Techniques for Generating Random Number
(cont.)
(Example)
Using the multiplicative congruential method, find
the period of the generator for a = 13, m = 26, and
X0 = 1, 2, 3, and 4. The solution is given in next
slide. When the seed is 1 and 3, the sequence has
period 16. However, a period of length eight is
achieved when the seed is 2 and a period of length
four occurs when the seed is 4.

50
Techniques for Generating Random Number
(cont.)
Period Determination Using Various seeds
i Xi Xi Xi Xi
0 1 2 3 4
1 13 26 39 52
2 41 18 59 36
3 21 42 63 20
4 17 34 51 4
5 29 58 23
6 57 50 43
7 37 10 47
8 33 2 35
9 45 7
10 9 27
11 53 31
12 49 19
13 61 55
14 25 11
15 5 15
16 1 3
51
Techniques for Generating Random Number
(cont.)
SUBROUTINE RAN(IX, IY, RN)
IY = IX * 1220703125
IF (IY) 3,4,4
3: IY = IY + 214783647 + 1
4: RN = IY
RN = RN * 0.4656613E-9
IX = IY
RETURN
END

52
Techniques for Generating Random Number
(cont.)
Linear Congruential Method:
Xi+1 = (aXi + c) mod m, i = 0, 1, 2....
(Example)
let X0 = 27, a = 17, c = 43, and m = 100, then
X1 = (17*27 + 43) mod 100 = 2
R1 = 2 / 100 = 0.02
X2 = (17*2 + 43) mod 100 = 77
R2 = 77 / 100 = 0.77
.........

53
Test for Random Numbers

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. Runs test. Tests the runs up and down or the runs
above and below the mean by comparing the
actual values to expected values. The statistic for
comparison is the chi-square.
3. Autocorrelation test. Tests the correlation
between numbers and compares the sample
correlation to the expected correlation of zero.

54
Test for Random Numbers (cont.)

4. Gap test. Counts the number of digits that appear


between repetitions of a particular digit and then
uses the Kolmogorov-Smirnov test to compare with
the expected number of gaps.
5. Poker test. Treats numbers grouped together as a
poker hand. Then the hands obtained are
compared to what is expected using the chi-square
test.

55
Test for Random Numbers (cont.)

In testing for uniformity, the hypotheses are as


follows:
H0: Ri ~ U[0,1]
H1: Ri ≠ U[0,1]
The null hypothesis, H0, reads that the numbers are
distributed uniformly on the interval [0,1].

56
Test for Random Numbers (cont.)

In testing for independence, the hypotheses are as


follows;
H0: Ri ~ independently
H1: Ri ≠ independently
This null hypothesis, H0, reads that the numbers are
independent. Failure to reject the null hypothesis
means that no evidence of dependence has been
detected on the basis of this test. This does not
imply that further testing of the generator for
independence is unnecessary.

57
Test for Random Numbers (cont.)

Level of significance α
α = P(reject H0 | H0 true)
Frequently, α is set to 0.01 or 0.05
(Hypothesis)
Actually True Actually False
Accept 1-α β
(Type II error)
Reject α 1-β
(Type I error)

58
Test for Random Numbers (cont.)

The Gap Test measures the number of digits between


successive occurrences of the same digit.
(Example) length of gaps associated with the digit 3.
4, 1, 3, 5, 1, 7, 2, 8, 2, 0, 7, 9, 1, 3, 5, 2, 7, 9, 4, 1, 6, 3
3, 9, 6, 3, 4, 8, 2, 3, 1, 9, 4, 4, 6, 8, 4, 1, 3, 8, 9, 5, 5, 7
3, 9, 5, 9, 8, 5, 3, 2, 2, 3, 7, 4, 7, 0, 3, 6, 3, 5, 9, 9, 5, 5
5, 0, 4, 6, 8, 0, 4, 7, 0, 3, 3, 0, 9, 5, 7, 9, 5, 1, 6, 6, 3, 8
8, 8, 9, 2, 9, 1, 8, 5, 4, 4, 5, 0, 2, 3, 9, 7, 1, 2, 0, 3, 6, 3
Note: eighteen 3’s in list
==> 17 gaps, the first gap is of length 10

59
Test for Random Numbers (cont.)
We are interested in the frequency of gaps.
P(gap of 10) = P(not 3) ××× P(not 3) P(3) ,
note: there are 10 terms of the type P(not 3)
= (0.9)10 (0.1)
The theoretical frequency distribution for randomly
ordered digit is given
x
by
F(x) = 0.1 Σ(0.9)n = 1 - 0.9x+1
n= 0
Note: observed frequencies for all digits are
compared to the theoretical frequency using the
Kolmogorov-Smirnov test.
60
Test for Random Numbers (cont.)

(Example)
Based on the frequency with which gaps occur,
analyze the 110 digits above to test whether they are
independent. Use α= 0.05. The number of gaps is
given by the number of digits minus 10, or 100. The
number of gaps associated with the various digits are
as follows:
Digit 0 1 2 3 4 5 6 7 8 9
# of Gaps 7 8 8 17 10 13 7 8 9 13

61
Test for Random Numbers (cont.)
Gap Test Example
Relative Cum. Relative
Gap Length Frequency Frequency Frequency F(x) |F(x) - SN(x)|
0-3 35 0.35 0.35 0.3439 0.0061
4-7 22 0.22 0.57 0.5695 0.0005
8-11 17 0.17 0.74 0.7176 0.0224
12-15 9 0.09 0.83 0.8147 0.0153
16-19 5 0.05 0.88 0.8784 0.0016
20-23 6 0.06 0.94 0.9202 0.0198
24-27 3 0.03 0.97 0.9497 0.0223
28-31 0 0.00 0.97 0.9657 0.0043
32-35 0 0.00 0.97 0.9775 0.0075
36-39 2 0.02 0.99 0.9852 0.0043
40-43 0 0.00 0.99 0.9903 0.0003
44-47 1 0.01 1.00 0.9936 0.0064

62
Test for Random Numbers (cont.)

The critical value of D is given by


D0.05 = 1.36 / √100 = 0.136
Since D = max |F(x) - SN(x)| = 0.0224 is less
than D0.05, do not reject the hypothesis of
independence on the basis of this test.

63
Test for Random Numbers (cont.)

Run Tests (Up and Down)


Consider the 40 numbers; both the Kolmogorov-Smirnov and Chi-square
would indicate that the numbers are uniformly distributed. But, not so.

0.08 0.09 0.23 0.29 0.42 0.55 0.58 0.72 0.89 0.91
0.11 0.16 0.18 0.31 0.41 0.53 0.71 0.73 0.74 0.84
0.02 0.09 0.30 0.32 0.45 0.47 0.69 0.74 0.91 0.95
0.12 0.13 0.29 0.36 0.38 0.54 0.68 0.86 0.88 0.91

64
Test for Random Numbers (cont.)

Now, rearrange and there is less reason to doubt independence.

0.41 0.68 0.89 0.84 0.74 0.91 0.55 0.71 0.36 0.30
0.09 0.72 0.86 0.08 0.54 0.02 0.11 0.29 0.16 0.18
0.88 0.91 0.95 0.69 0.09 0.38 0.23 0.32 0.91 0.53
0.31 0.42 0.73 0.12 0.74 0.45 0.13 0.47 0.58 0.29

65
Test for Random Numbers (cont.)

Concerns:
 Number of runs
Length of runs
Note: If N is the number of numbers in a
sequence, the maximum number of runs is
N-1, and the minimum number of runs is
one.
If “a” is the total number of runs in a
sequence, the mean and variance of “a” is
given by
66
Test for Random Numbers (cont.)

µa = (2n - 1) / 3
σ a2 = (16N - 29) / 90
For N > 20, the distribution of “a” approximated
by a normal distribution, N(µa , σ a2 ).
This approximation can be used to test the
independence of numbers from a generator.
Z0 = (a - µa) / σa

67
Test for Random Numbers (cont.)
Substituting for µa and σa ==>
Za = {a - [(2N-1)/3]} / {√(16N-29)/90},
where Z ~ N(0,1)
Acceptance region for hypothesis of
independence -Zα/2 ≤ Z0 ≤ Zα/2

α /2 α /2

-Zα / 2 Zα / 2

68
Test for Random Numbers (cont.)

(Example)
Based on runs up and runs down, determine
whether the following sequence of 40 numbers is
such that the hypothesis of independence can be
rejected where α = 0.05.

0.41 0.68 0.89 0.94 0.74 0.91 0.55 0.62 0.36 0.27
0.19 0.72 0.75 0.08 0.54 0.02 0.01 0.36 0.16 0.28
0.18 0.01 0.95 0.69 0.18 0.47 0.23 0.32 0.82 0.53
0.31 0.42 0.73 0.04 0.83 0.45 0.13 0.57 0.63 0.29

69
Test for Random Numbers (cont.)
The sequence of runs up and down is as follows:
+++−+−+−−−++−+−−+−+−−+−−+−++− −++−+−−++−
There are 26 runs in this sequence. With N=40 and a=26,
µa = {2(40) - 1} / 3 = 26.33 and
2
σ a = {16(40) - 29} / 90 = 6.79
Then,
Z0 = (26 - 26.33) / √(6.79) = −0.13
Now, the critical value is Z0.025 = 1.96, so the
independence of the numbers cannot be rejected
on the basis of this test.
70
Test for Random Numbers (cont.)

Poker Test - based on the frequency with


which certain digits are repeated.
Example:
0.255 0.577 0.331 0.414 0.828 0.909
Note: a pair of like digits appear in each
number generated.

71
Test for Random Numbers (cont.)

In 3-digit numbers, there are only 3 possibilities.


P(3 different digits) =
(2nd diff. from 1st) * P(3rd diff. from 1st & 2nd)
= (0.9) (0.8) = 0.72
P(3 like digits) =
(2nd digit same as 1st) ∗ P(3rd digit same as 1st)
= (0.1) (0.1) = 0.01
P(exactly one pair) = 1 - 0.72 - 0.01 = 0.27

72
Test for Random Numbers (cont.)

(Example)
A sequence of 1000 three-digit numbers has been
generated and an analysis indicates that 680 have
three different digits, 289 contain exactly one pair
of like digits, and 31 contain three like digits. Based
on the poker test, are these numbers independent?
Let α = 0.05.
The test is summarized in next table.

73
Test for Random Numbers (cont.)

Observed Expected (Oi - Ei)2


Combination, Frequency, Frequency, -----------
i Oi Ei Ei
Three different digits 680 720 2.24
Three like digits 31 10 44.10
Exactly one pair 289 270 1.33
------ ------ -------
1000 1000 47.65

The appropriate degrees of freedom are one less than


the number of class intervals. Since χ20.05, 2 = 5.99
< 47.65, the independence of the numbers is
rejected on the basis of this test.

74
Refences:
• Introduction to Parallel RNGs
http://sprng.cs.fsu.edu/Version1.0/paper/index.html
• Random Number Generation on Parallel
Computer Systems
http://www.npac.syr.edu/projects/reu/reu94/cstoner
/proposal/proposal.html
• SPRNG (Scalable Parallel Pseudo Random
Number Generators Library)
http://sprng.cs.fsu.edu/
References (continued)

• A. Srinivasan, D. Ceperley and M. Mascagni,


Testing Parallel Random Number Generators
http://sprng.cs.fsu.edu/links.html
• M. Mascagni, D. Ceperley and A. Srinivasan,
SPRNG: A Scalable Library for Pseudorandom
Number Generation
http://sprng.cs.fsu.edu/links.html
• Ian Foster, Designing and Building Parallel
Programs
• D. E. Knuth, The Art of Computer Programming,
Volume 2, Seminumerical Algorithms, Third Edition

You might also like