1. Old-Fashioned Randomness 📜
Slides 1-5The Pencil Method
A pencil with sides A, B, C, D. Useful for exams, but not for scientific computing! It lacks speed and precision.
Random Number Tables
Before computers, people used books full of random digits. These tables taught us two fundamental properties of pseudo-randomness:
- You need a seed to start.
- It relies on recursive operations.
True vs Pseudo Generators
Measures physical phenomena (thermal noise, photoelectric effect). Essential for cryptography.
Computational algorithms. Deterministic sequences determined by a seed. Good enough for scientific work.
2. Linear Congruential Generator (LCG)
Slides 7-11A classical algorithm. Simple, commonly used, but potentially dangerous.
Where $a, c$ are scaling constants and $M$ is the modulus. The period is at most $M$.
Example: A Bad LCG ($M=100$)
Watch how quickly the sequence repeats.
Example: Park-Miller RNG (Good)
Uses $a=16807, c=0, M=2^{31}-1$. The period is almost $2^{31}-1$.
⚠️ The RANDU Disaster
IBM used $a=65539, M=2^{31}$ in the 1960s. It produces numbers that fall into just 15 planes in 3D space!
3. Bitwise Generators 💻
Slides 19-27XORSHIFT Algorithm
$x \leftarrow x \text{ xor } (x \ll a_2)$
$x \leftarrow x \text{ xor } (x \gg a_3)$
Multiply With Carry (MWC)
$(x \& \text{mask}) \cdot a + (x \gg 32)$
Combined Generator (The Beast)
Combining XORSHIFT + MWC yields a massive period of $\approx 10^{37}$.
4. Non-Uniform Distributions 📊
Slides 30-50❌ The Wrong Way
Just plugging random numbers into $f(x)$ does not produce distribution $f(x)$.
✅ Method 1: Hit-or-Miss (Rejection Sampling)
Generate random $(x, y)$. Keep $x$ only if $y < f(x)$. Simple but inefficient.
✅ Method 2: Inverse Transform
Example: Exponential Decay $f(x) = e^{-x}$. Cumulative $W(x) = 1 - e^{-x}$. Inverse: $x = -\ln(1-r)$.
Gaussian: Box-Muller
Transforming uniform coords to polar/Gaussian.
Gaussian: CLT Summation
Sum of 12 uniform randoms $\to$ Gaussian.
5. Monte Carlo Integration 🎯
Slides 52-556D Integral Example
Integrating $\sum \sin$ terms over a 6D hypercube. Grid methods fail here!
👐 Hands-On Session
Practice 1: Step Function
Generate distribution for:
f(x) = 2 (1 < x <=2)
...
f(x) = 9 (8 < x <=9)
Practice 2: Complex Model
Generate 10k events for the Higgs fit model: