3. Random Number Generation
Every random variate in a simulation is built from i.i.d. U(0,1) numbers; these notes cover where those numbers come from and what makes a generator good.
Motivation. Consider simulating an queue (Markovian, i.e. exponential, interarrival times; exponential service times; one server). We must repeatedly generate , whose c.d.f. is , . This can be done from a single uniform random number:
- Generate .
- Return .
Why it works: setting and solving for gives ; since as well, we may use instead. Then
The same idea applies to other distributions: every random variate in a simulation is built from i.i.d. numbers.
Goal of this chapter. Produce a sequence of i.i.d. random numbers, i.e. numbers with p.d.f.
Three alternative sources of “random” numbers
1. True random numbers (from physical experiments)
- Draw numbered balls from an urn.
- Electrical circuits: a hardware random number machine, e.g. ERNIE (Electronic Random Number Indicator Equipment).
- Disadvantages:
- Not reproducible. Reproducibility matters in simulation: it makes debugging easier, and it gives sharper comparisons when two alternative systems are run on the same random inputs.
- Difficult to implement.
- Slow.
2. Pseudo-random numbers — a completely deterministic sequence that is statistically indistinguishable from a true random sequence. This is what simulation uses in practice, and what the rest of the chapter is about.
3. Quasi-random numbers (used in Monte Carlo integration rather than in simulation)
An integral over is an expectation under , because the p.d.f. equals there:
So generate and estimate the integral by
By the CLT the error of this estimator is of order . The idea of quasi-random numbers is to replace the random sequence by a deterministic sequence that covers more evenly; this improves the error rate to order . Such sequences are not i.i.d., so they are useless as simulation inputs, but for integration the even coverage is exactly what helps.
3.1 Random Number Generators (RNGs)
Desired properties of an RNG
- Uniformity: the sequence should appear to be uniformly distributed on .
- Independence: terms in the sequence should not be correlated.
- Reproducibility: one must be able to reproduce a particular stream of random numbers (e.g. from a seed).
- Fast, with low memory usage.
- Long period. A deterministic generator eventually loops. The segment of non-repeating numbers is called a cycle, and its length is the period of the RNG.
flowchart LR
u1(("u₁")) --> u2(("u₂")) --> u3(("u₃")) --> d[". . ."] --> uP(("u_P")) --> u1
The sequence repeats after terms, so the period must be far longer than the number of random numbers a simulation will consume.