Simulation: making randomness you want out of randomness you have
PROB · Chapter 613 min readAsked at Jane Street, Optiver, SIG, Two Sigma
After this lesson you should be able to
- Turn a uniform into any distribution by inverting its CDF.
- Build a fair coin from a biased one, and a d7 from a d6.
- State the Monte Carlo error rate and name two ways to reduce it.
Two related families of question show up. One asks you to manufacture one kind of randomness from another — a fair coin from a biased one, a seven-sided die from a six-sided one — and is really about symmetry and expected waiting times. The other asks how accurate a simulation is, and is really about .
Equation 6.1
The inverse transform
Feed a uniform through the inverse CDF and you get the distribution you wanted. This is the general answer to "how would you sample from this?", and it is why a uniform generator is all a library needs.
- The quantile function. For a discrete law it is a lookup down the cumulative table.
- The exponential case, which is worth knowing by heart.
| Method | Needs | Fails when |
|---|---|---|
| Inverse transform | A computable | The CDF has no closed-form inverse — the normal, for instance |
| Rejection sampling | A proposal density that dominates the target | The acceptance rate is low, which wastes draws |
| Box–Muller | Two uniforms | Nothing much — it is the standard normal recipe |
Derivation 6.3
A fair coin from a biased one
Von Neumann’s trick. The bias is unknown and need not be measured.
Pair the flips and read only the mixed outcomes.
The two mixed outcomes are equally likely whatever is — that symmetry is the whole idea.
Symmetry is the tool, not arithmetic. Notice that nothing in the von Neumann argument requires knowing . That is the point: you are not correcting for the bias, you are finding two outcomes that the bias treats identically and ignoring everything else. The same instinct solves the d7-from-a-d6 problem — roll twice for 36 equally likely outcomes, use 35 of them in seven groups of five, and re-roll on the thirty-sixth — and it is why "find the symmetry, discard the rest" is the first thing to try on any construction question.
The rest of this lesson is in Premium
You have read the opening. 14 more sections follow, including 6 worked examples and 3 quick checks.
Nothing is charged for 7 days, and you can cancel before then. Or read Arithmetic that survives a clock in full, free.