Random numbers
Section of Simulation, part of Probability
Random numbers
| Type | Section |
| Taught in | Simulation |
| Part | Probability |
Coins, dice and roulette wheels were the first random number generators, and physical devices such as noise diodes and Geiger counters followed. Simulation abandoned them: they are slow, their output cannot be reproduced, and their numbers turn out to be biased and dependent. Almost every generator in use today is a short deterministic recursion whose output passes the statistical tests a truly random sequence would. Such numbers are called pseudorandom.
Definition 1 (Linear congruential generator) A linear congruential generator produces integers by the recursion
X_{i+1}=(aX_i+c)\bmod m,
starting from a seed X_0, with positive integer multiplier a, increment c and modulus m. The pseudorandom numbers are U_i=X_i/m. With c=0 it is a multiplicative congruential generator.
Each X_i lies in \{0,1,\ldots,m-1\}, so the sequence must repeat within m steps: its period is at most m. With a=c=X_0=3 and m=5, the recursion gives 3,2,4,0,3,\ldots, with period 4. Only carefully chosen constants give long periods and good statistical behaviour; a classic choice for 32-bit arithmetic is the multiplicative generator with m=2^{31}-1, a prime, and a=7^5=16807. Modern libraries use longer recursions with periods far beyond any simulation’s needs.
A uniform generator, then, returns numbers that behave as independent draws from \operatorname{U}[0,1]. Setting a seed makes the sequence repeatable: the same seed produces the same stream, which is what lets a simulation be checked and its bugs reproduced. In Python, np.random.seed(1234) followed by np.random.rand(5) returns the same five numbers every time. Every method below assumes such a stream and nothing else.
Used in
- Taught in Simulation
- All 4 questions on Simulation
See also
Linear congruential generator · Inverse-transform method · Acceptance–rejection method · Draws from the usual families · Box–Muller method · Cauchy distribution · Random seed