Random-Number Generation: Discrete-Event System Simulation
Random-Number Generation: Discrete-Event System Simulation
Random-Number
Generation
2
Properties of Random Numbers
Two important statistical properties:
Uniformity
Independence.
Random Number, Ri, must be independently drawn from a
uniform distribution with pdf:
1, 0 x 1
f ( x)
0, otherwise
1
2
1 x 1
E ( R ) xdx
0 2
0
2
Figure: pdf for
random numbers
3
Generation of Pseudo-Random Numbers
“Pseudo”, because generating numbers using a known
method removes the potential for true randomness.
Goal: To produce a sequence of numbers in [0,1] that
simulates, or imitates, the ideal properties of random numbers
(RN).
When Generating pseudo Random Numbers, Certain errors
or problems can occur including:
Departure from uniformity
Discrete instead of continuous
Too high or too low mean / variance
Dependency
Autocorrelation,
trend,
several point above the mean followed by points lower the mean
4
Generation of Pseudo-Random Numbers
Important considerations in RN routines:
Fast
Portable to different computers
Have sufficiently long cycle (avoid cycling degenerating)
Replicable
Closely approximate the ideal statistical properties of uniformity
and independence.
5
Techniques for Generating Random
Numbers
6
Linear Congruential Method [Techniques]
8
Characteristics of a Good Generator
[LCM]
Maximum Density
Such that he values assumed by Ri, i = 1,2,…, leave no large
gaps on [0,1]
Problem: Instead of continuous, each Ri is discrete
Solution: a very large integer for modulus m
Maximum Period
To achieve maximum density and avoid cycling.
Achieve by: proper choice of a, c, m, and X0.
Most digital computers use a binary representation of
numbers
Speed and efficiency are aided by a modulus, m, to be (or close
to) a power of 2.
9
Combined Linear Congruential Generators
[Techniques]
Reason: Longer period generator is needed because of the
increasing complexity of stimulated systems.
Approach: Combine two or more multiplicative congruential
generators.
Let Xi,1, Xi,2, …, Xi,k, be the ith output from k different
multiplicative congruential generators.
The jth generator:
Has prime modulus mj and multiplier aj and period is mj-1
m-1]
Wi,j = Xi,j -1 is approx ~ Uniform on integers in [1, m-2]
10
Combined Linear Congruential Generators
[Techniques]
Suggested form:
Xi
k m , Xi 0
X i (1) X i , j mod m1 1
j 1
Hence, Ri 1
j 1 m 1
1 , Xi 0
m1
The coefficient:
Performs the
subtraction Xi,1-1
11
Combined Linear Congruential Generators
[Techniques]
Example: For 32-bit computers, L’Ecuyer [1988] suggests combining
k = 2 generators with m1 = 2,147,483,563, a1 = 40,014, m2 =
2,147,483,399 and a2 = 20,692. The algorithm becomes:
Step 1: Select seeds
X1,0 in the range [1, 2,147,483,562] for the 1st generator
13
Tests for Random Numbers
Two categories:
Testing for uniformity:
H0: Ri ~ U[0,1]
H1: Ri ~/ U[0,1]
Failure to reject the null hypothesis, H0, means that evidence of
non-uniformity has not been detected.
Testing for independence:
H0: Ri ~ independently
H1: Ri ~/ independently
Failure to reject the null hypothesis, H0, means that evidence of
dependence has not been detected.
Level of significance the probability of rejecting H0 when it
is true: = P(reject H0|H0 is true)
14
Tests for Random Numbers
When to use these tests:
If a well-known simulation languages or random-number
generators is used, it is probably unnecessary to test
If the generator is not explicitly known or documented, e.g.,
spreadsheet programs, symbolic/numerical calculators, tests
should be applied to many sample numbers.
Types of tests:
Theoretical tests: evaluate the choices of m, a, and c without
actually generating any numbers
Empirical tests: applied to actual sequences of numbers
produced. Our emphasis.
15
Test for Random Numbers
16 Random Numbers
Test for Random Numbers (cont.)
17 Random Numbers
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)
18 Random Numbers
Frequency Tests [Tests for RN]
Test of uniformity
Two different methods:
Kolmogorov-Smirnov test
Chi-square test
19
Kolmogorov-Smirnov Test [Frequency Test]
20
Kolmogorov-Smirnov Test [Frequency Test]
21
Chi-square test [Frequency Test]
22
Test for Random Numbers (Run Tests )
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
23 Random Numbers
Run test (Up and Down)
24 Random Numbers
Run test (Up and Down)
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
25 Random Numbers
Run test (Up and Down)
a = (2n - 1) / 3
2
a = (16N - 29) / 90
For N > 20, the distribution of “a” approximated
by a normal distribution, N(a , a ).
2
-Z / 2
Z / 2
27 Random Numbers
Run test (Up and Down)
(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
28 Random Numbers
Run test (Up and Down)
29 Random Numbers
Run test (above and below the mean)
Run Tests (above and below the mean)
Consider the following 40 numbers, what do you notice about
them?:
0.63 0.72 0.79 0.81 0.52 0.94 0.83 0.93 0.87 0.67
0.54 0.83 0.89 0.55 0.88 0.77 0.74 0.95 0.82 0.86
0.43 0.32 0.36 0.18 0.08 0.19 0.18 0.27 0.36 0.34
0.31 0.45 0.49 0.43 0.46 0.35 0.25 0.39 0.47 0.41
•Expected mean = (0.00 + 0.99)/2 = 0.495
•The first, and last 20 numbers are above and
below the mean respectively.
30
Run test (above and below the mean)
Let n1, n2 be the number of values above and
below the mean respectively.
maximum number of runs = N = n1, n2. and the
minimum number of runs =1.
2n1n2 1
b
N 2
2n1n2 (2n1n2 N )
b
2
N 2 ( N 1)
2(18)(22) 1
b 20.3
40 2
2(18)(22)[(18)(22) 40)
b
2
9.54
40 (40 1)
2
17 20.3
Z0 1.07
9.54
33
Run test (length of runs)
For the following set of numbers:
0.16 0.27 0.58 0.63 0.45 0.21 0.72 0.87
0.27 0.87 0.27 0.15 0.92 0.85 …
34
Run test (length of runs)
Let Yi be the number of runs of length I in a
sequence of N numbers, then..
For runs up and down:
E(Y ) : 2
2 3 2
N (i 3i 1) - (i 3i i 4) : when..i N 2
i (i 3)!
E(Y ) : 2 : when..i N 1
i N!
35
Run test (length of runs)
For runs above and below the mean:
Nwi
E (Yi ) , , N 20
E(I )
n1 i n2 n1 n2 i
wi ( ) ( ) ( )( ) , , N 20
N N N N
n1 n2
E(I ) , , N 20
n2 n1
i 1 E (Yi )
L=N-1 for runs up and down, and N for runs above and
below the mean.
If the numbers are independent, is chi square
distributed with L-1 degrees of freedom.
02
37
Run test (length of runs)
Example 7.10 (length of run up and down)
38
Run test (length of runs)
Example 7.10 (length of run up and down)
40
Run test (length of runs)
Example 7.11 (length of runs above and below the mean)
41
Run test (length of runs)
42
Run test (length of runs)
43
Tests for Autocorrelation [Tests for RN]
44
Tests for Autocorrelation [Tests for RN]
45
Example [Test for Autocorrelation]
Test whether the 3rd, 8th, 13th, and so on, for the following
output on P. 265.
Hence, = 0.05, i = 3, m = 5, N = 30, and M = 4
47
Gap test
49
Steps for the Gap test
50
Gap test - Example
51
Gap test - Example
52
Poker test
54
Poker test - Example
55
Summary
In this chapter, we described:
Generation of random numbers
Testing for uniformity and independence
Caution:
Even with generators that have been used for years, some of
which still in used, are found to be inadequate.
This chapter provides only the basic
Also, even if generated numbers pass all the tests, some
underlying pattern might have gone undetected.
56