Professional Documents
Culture Documents
Random-Number
Generation
Dr. Banu al
Random Number
Generators
Without random numbers, we cannot do
Stochastic Simulation
Most computer languages have a
subroutine, object or function generating
random numbers (uniformly distributed)
Simulation languages provide more than
that (you can get random samples from
many distributions)
How do they generate it?
How can we test their randomness?
Pseudo-Random Numbers
Approach:
Arithmetically
generation
(calculation) of random numbers
Pseudo, because generating numbers using
a known method removes the potential for true
randomness. (Because these numbers are
produced using a deterministic algorithm)
Goal: To produce a sequence of numbers
in [0,1) that simulates, or imitates, the
ideal properties of random numbers (RN).
Pseudo-Random Numbers
Pseudo-Random Numbers
Important properties of good random
number routines:
Fast
Portable to different computers
Have sufficiently long cycle
Replicable
Verification and debugging
Use identical stream of random
numbers for different systems
Pseudo-Random Numbers
Problems when generating pseudorandom numbers
The generated numbers might not be
uniformly distributed
The
generated
numbers
might
be
discrete-valued instead of continuousvalued
The mean of the generated numbers
might be too high or too low
The variance of the generated numbers
might be too high or too low
Pseudo-Random Numbers
There might be dependence:
Autocorrelation between numbers
Numbers successively higher or
lower than adjacent numbers
Several numbers above the mean
followed by several numbers below the
mean
Generating Random
Numbers
1. Midsquare method
2. Linear Congruential Method (LCM)
3. Combined Linear Congruential
Generators (CLCG)
4. Random-Number Streams
Midsquare method
First
Midsquare method
Example: = 7182
Problem:
Generated
numbers tend to
Note:
X1
X2
X3
X4
=
=
=
=
R 1 = 0.02
R 2 = 0.77
R 3 = 0.52
R 4 = 0.27
Maximum Period
To achieve maximum density and avoid cycling
Achieved by proper choice of a, c, m, and X 0
For m = 2b, c 0 and relatively prime to m and a =
1+4k, the longest possible period P = m.
For m = 2b, c = 0, X0 (seed) odd, and a = 3+8k or a
= 5+8k, the longest possible period P = m/4
For m a prime number, etc.. P = m-1
A random-number stream:
Refers to random numbers obtained by using a starting
seed
If the streams areS bvalues
X b (i 1) apart, then stream i could defined by
i
starting seed:
Older generators: b = 105; Newer generators: b = 1037.
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.
Frequency Tests
Test of uniformity
Two different methods:
Kolmogorov-Smirnov test
Chi-square test
Chi-square test
Chi-square test
Example
27
Summary