Random-Number Generation: Discrete-Event System Simulation
Random-Number Generation: Discrete-Event System Simulation
Random-Number
Generation
2
Discuss characteristics and the generation of
random numbers.
• Subsequently, introduce tests for randomness:
• Frequency test
• Autocorrelation test
3
Random Number Generators
Random number generation is a method of
producing a sequence of numbers that lack any
discernible pattern.
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
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
Calculate variance? random numbers
6
Continue
Some consequences of the informality and
independence properties are the following:
1. If the interval [0,1] is divided into n classes,or
subinterval of equal length , the expected
number of observations in each interval is N/n,
where N is the total number of observations.
2. The probability of observing a values in a
particular interval is independent of the previous
values drawn
7
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).
Important considerations in RN routines:
Fast
Portable to different computers
Have sufficiently long cycle
Replicable
• Verification and debugging
• Use identical stream of random numbers for different systems
Closely approximate the ideal statistical properties of uniformity and
independence.
8
Techniques for Generating Random
Numbers
Linear Congruential Method (LCM).
Widely used
Combined Linear Congruential Generators (CLCG).
Random-Number Streams.
9
Linear Congruential Method [Techniques]
Xi
Ri , i 1,2,...
m
10
Continue
11
Example [LCM]
12
Linear Congruential Generator
Example Sequences:
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)
… …
13
Characteristics of a Good Generator
[LCM]
Maximum Density
Such that the 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
Approximation appears to be of little consequence
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.
14
15
Example
16
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]
17
Combined Linear Congruential Generators
[Techniques]
Suggested form:
Xi
k m , X i 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
18
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
20
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)
21
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.
22
Frequency Tests [Tests for RN]
Test of uniformity
Two different methods:
Kolmogorov-Smirnov test
Chi-square test
23
Kolmogorov-Smirnov Test [Frequency Test]
24
Kolmogorov-Smirnov Test [Frequency Test]
25
Chi-square test [Frequency Test]
26
Chi-square Test: Example
27
Tests for Autocorrelation [Tests for RN]
28
Tests for Autocorrelation [Tests for RN]
29
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
31
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.
32