🎲Randomness and Estimation
Random Numbers and Monte Carlo Simulation
Pseudo-random generators and their flaws, sampling distributions, numpy.random.Generator, confidence intervals
Random numbers fall mainly in the planes, 1968
In the 1960s, one of the most widely distributed random-number generators in the world was RANDU, part of IBM's Scientific Subroutine Package for the System/360 family of computers. It was simple and fast: multiply the previous integer by 65539 and keep the remainder after dividing by . Its numbers passed the usual statistical checks: they were spread evenly between 0 and 1, with the right mean and variance. Thousands of simulations — of nuclear reactors, of queues, of physical systems — were built on it.
In 1968 George Marsaglia of Boeing Scientific Research Laboratories published a short paper with a memorable title: Random numbers fall mainly in the planes. He proved that the successive outputs of every generator of RANDU's type, taken in groups of , lie on a small number of parallel hyperplanes. For RANDU the result was spectacular: every triple of consecutive numbers lies on one of just 15 planes in the unit cube. Any simulation that used three consecutive numbers as a point in space — a direction, a position, three random loads — had been sampling only those planes.
Results computed with RANDU went on appearing in the scientific literature for years afterwards.
Monte Carlo methods (lesson 8-5) need streams of numbers that behave as if independent and uniformly distributed. A computer is deterministic, so it produces pseudo-random numbers: a recurrence whose outputs pass statistical tests of randomness. Reproducibility is then a feature: the same seed gives the same stream, so a simulation can be repeated exactly — which is why every lab in this course sets one.
💡Linear congruential generators and their lattice
The classic generator is the linear congruential generator , . For RANDU, , , . Squaring the multiplier modulo gives , so
Every triple satisfies one of 15 integer equations — 15 planes. Its one-dimensional statistics are fine (mean 0.503, variance 0.0832 against 0.5 and 0.0833); only the joint distribution reveals the flaw. Modern generators — the Mersenne Twister (1998), PCG (2014, NumPy's default since 2019), Philox and xoshiro — are designed and tested against such structure in hundreds of dimensions.
Derivation
RANDU's planes in three lines
Square the multiplier exactly:
Modulo the term vanishes, so . Two steps of the generator multiply by , hence
Divide by : is a whole number. With every between 0 and 1 that whole number lies between and , so only a handful of values — 15 in practice — are possible, and each defines a plane in the unit cube. A single unlucky choice of multiplier, made for speed, put every triple of a world-standard generator on 15 sheets.
Any one who considers arithmetical methods of producing random digits is, of course, in a state of sin.
Sampling other distributions. Uniform numbers are turned into whatever the model needs:
- Inverse transform: if is uniform and is a cumulative distribution, has distribution . Wind speeds with a Weibull distribution, , come from .
- Box–Muller (1958): two uniforms give two independent standard normals, and .
- In practice, use
numpy.random.default_rng(seed)and its methods (normal,weibull,gumbel,multivariate_normal, …), which implement fast, tested algorithms.
Check samples against the target distribution with a goodness-of-fit test such as Kolmogorov–Smirnov (
scipy.stats.kstest).Derivation
Why inverse transform and Box–Muller work
Inverse transform. Let be uniform on , so , and let be increasing. Then
which is exactly the statement that has distribution . For the Weibull, solve for : , , so .
Box–Muller. Two independent standard normals have joint density , which depends only on the radius . So their angle is uniform on — that is . For the radius, the probability of landing outside radius is a one-line polar integral:
Inverting that by the rule above (with replaced by , which is just as uniform) gives . Point is then a pair of independent normals.
📐Wind power is not average wind cubed
Wind speed at a site follows a Weibull distribution with , m/s (mean 7.09 m/s). Turbine power is proportional to . From 100,000 sampled speeds, the mean of is 674.5 while the cube of the mean speed is 353.4: designing with the average wind would predict only 52% of the true average power. Nonlinear models of uncertain inputs must be averaged over the distribution, not evaluated at the average — the most common error in uncertainty analysis.
Derivation
The 52%, exactly — and the confidence interval for a probability
The wind. The Weibull distribution has moments (a standard integral). With , :
Because curves upwards, the strong gusts add far more power than the calm spells remove: the mean of the cube exceeds the cube of the mean (Jensen's inequality). The 100,000-sample estimates, 674.5 and 353.4, give the same 52%.
The interval. Counting failures among independent trials, each failing with probability , gives a binomial count with variance . The estimate therefore has variance (dividing by divides a variance by ). For large the count is nearly normal, and 95% of a normal distribution lies within 1.96 standard deviations — which gives the interval in the box above.
💡Confidence intervals
A Monte Carlo estimate is itself random. For a probability estimated from samples, the standard error is , and an approximate 95% confidence interval is . For a steel tie with normally distributed resistance and a Gumbel-distributed extreme load, give , , ; numerical integration of gives 0.00742. Always report the interval: an estimate of from 2 failures in 20,000 samples is barely an estimate at all. Rare events need importance sampling or structural-reliability methods (FORM/SORM) rather than brute force.
💡Where you will use this
Structural and Geotechnical reliability: failure probabilities with uncertain loads, strengths and soil properties. Rocket Propulsion and Guidance: Monte Carlo dispersion analysis — thousands of simulated flights with sampled thrust, mass and wind. Orbital Mechanics: collision probabilities. GNSS and Navigation: simulated sensor noise to test filters. Every course: whenever a number is uncertain, sampling is the honest way to see what follows.
📚Further reading
- Donald Knuth, The Art of Computer Programming, Volume 2: Seminumerical Algorithms (3rd ed., Addison-Wesley, 1997), chapter 3, 'Random Numbers' — linear congruential generators, the spectral test and transformation methods.
- George Marsaglia, 'Random numbers fall mainly in the planes', Proceedings of the National Academy of Sciences 61(1), 25–28 (1968).
- Melissa O'Neill, PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation, Harvey Mudd College technical report HMC-CS-2014-0905 (2014) — the generator behind
numpy.random.default_rng.
↓But there is a problem
Monte Carlo shows how uncertainty in the inputs becomes uncertainty in the answer — by brute force, thousands of runs at a time. Often you need the answer in one calculation, every second, on board.
On 10 February 2009 a screening service that checks the whole public satellite catalogue for close approaches predicted that two satellites over Siberia would pass 584 m apart. It was not considered a dangerous number. The prediction was missing one thing: how uncertain it was.