Random Number Generators: Professor Karl Sigman Columbia University Department of IEOR New York City USA
Random Number Generators: Professor Karl Sigman Columbia University Department of IEOR New York City USA
Random Number Generators: Professor Karl Sigman Columbia University Department of IEOR New York City USA
1/17
Introduction
P(y < U ≤ x) = x − y.
2/17
Introduction
3/17
Introduction
import random
U = random.random()
Once random is imported, then each time you use the command
U = random.random()
you receive a new uniform number within [0, 1).
4/17
Introduction
5/17
Introduction
6/17
Pseudorandom numbers
It turns out that the numbers generated by a computer are not really
random nor independent as we said, but what are called
Pseudorandom numbers.
This means that they appear, for all practical purposes, to be random
(and independent) in the sense that they would pass various
statistical tests for checking the random/independent property. We
thus can use them in our simulations as if they were truly
random—and we do.
7/17
Pseudorandom numbers
(0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1).
I tell you that I flipped a fair coin 25 times where 1 = Head (H), and
0 = Tails (T).
How can you check with certainty that I am telling the truth?
8/17
Pseudorandom numbers
9/17
Linear Congruential Generators
The most common and easy to understand and implement random
number generator is called a Linear Congruential Generator (LCG)
and is defined by a recursion as follows:
Zn+1 = (aZn + c) mod m, n ≥ 0,
Un = Zn /m,
where 0 < a < m, 0 ≤ c < m are constant integers, and mod m
means modulo m which means you divide by m and leave the
remainder. For example 6 mod 4 = 2, 2 mod 4 = 2, 7 mod 4 = 3,
12 mod 4 = 0. Thus all the Zn fall between 0 and m − 1; the Un are
thus between 0 and 1.
11/17
Linear Congruential Generators
12/17
Linear Congruential Generators
To illustrate, consider
with Z0 = 0. Then
13/17
Linear Congruential Generators
If we increase c to c = 16,
(Z0 , Z1 , . . . , Z15 ) = (0, 1, 6, 15, 12, 13, 2, 11, 8, 9, 14, 7, 4, 5, 10, 3),
14/17
Linear Congruential Generators
15/17
Linear Congruential Generators
16/17
More sophisticated generators
17/17