Random Numbers & Generation
Random Numbers & Generation
&
Their Generation
Submitted By:
Karandeep Singh
C08323
C.S.E. , 6TH Sem.
Overview
Importance of random number generation
Desiderata for a random number generator
(RNG)
Methods for generating random numbers
Methods for testing random number generators
Additional considerations
Summary
C08323
Importance of
Random Number Generation
In simulation, we need them to model stochastic
variation (if not, why are we simulating?)
We really need pseudo-random numbers, not
random numbers, so that:
– We can verify and validate more easily
– We can test system alternatives under equal
conditions
C08323
Desiderata for a RNG
1. It should generate independent values
faithfully mimicking U[0,1]
2. The RNG should be fast
3. The RNG should need little storage
4. The RNG should be portable
5. The RNG should have a long cycle
6. The random variates should be
replicable and available “by stream”
C08323
The Mid-Square Method
Startwith a 4-digit number, the seed
Square it to obtain an 8-digit number,
with zero fill on left if needed
Middle 4 digits of those 8 are next
random number
Let’s try it with 7182 as seed
C08323
The Fibonacci Method
Zi = (Zi-1 + Zi-2) mod m
This type of generator usually has a
period exceeding m
At first, it was praised in the literature
Oops – consecutive output values
satisfying the inequality Zi-2 <Zi<Zi-1 are
impossible1
C08323
That inequality should be satisfied 1/6 of
The Linear Congruential
Method
Xi+1 = (aXi + c) mod m
X0 is the seed
– a is the constant multiplier
– c is the increment
– m is the modulus
If c≠0, “mixed congruential method”
If c=0, “multiplicative congruential
method” C08323
Longest (Best) Cycle
To obtain the longest possible cycle:
1.Set m = 2b (consider computer word size)
2.Set c ≠ 0 (mixed congruential method)
3.Ensure GCD(c,m) = 1
4.Ensure a ≡ 1 mod 4
C08323
What If Longer Cycle
Needed?
On most computers, these methods
achieve a cycle of length ≈ 109
Work in the 1980s by Pierre L’Ecuyer, a
world expert in RNGs, produced
combined linear congruential generators
with cycles of length ≈ 1018
His more recent work has produced
generators with cycles of length ≈ 1057C08323
Tausworthe Generators
These generators operate directly with
bits to form random numbers
Essentially independent of computer’s
word size
Huge cycles (e.g., > 10156 achieved)
Empirical evidence for their superiority
lacking
GPSS/H abandoned use of these, C08323
C08323
Tests for Random Numbers
5. The Poker test
For example, in random numbers
containing 4 decimal digits, how often
do the following appear? –
– “no pair,” e.g., 0.3785
– “one pair,” e.g., 0.2278, 0.2782,
0.2728,0.7822
– “two pairs,” e.g., 0.2323, 0.3322,
0.2332 C08323
Distributions Other than
U[0,1]
Basic RNGs are U[0,1]
To obtain other distributions from
U[0,1], use:
1. Inverse Transform technique
2. Direct Transformation (for normal or
lognormal)
3. Convolution
C08323
4. Acceptance-Rejection
Antithetic Variates
Two RNGs are antithetic if
corresponding numbers (e.g., the 984th
number from each RNG) add to 1. That
is, if one random number is high, its
counterpart is low, and vice versa.
Excellent for variance reduction among
consecutive pairs of replications.
C08323
Summary
RNGs are a specialized field of study
within simulation research
Understanding the basic principles of
RNGs, and knowing the method used
by the RNG in the software you’re
using, is far superior to blind trust in a
“black box”
C08323