Making a Fair Coin From a Biased One
Von Neumann's trick throws away exactly the information that carries the bias, by only ever looking at pairs of flips that disagree.
Prerequisites: How to Attack a Brainteaser
You're handed a coin that lands heads with some unknown probability — you don't know , and it could be close to 0 or 1. Using only this coin, produce a perfectly fair 50/50 outcome. It looks like you need to know to correct for it. You don't.
The puzzle and the trick
Given a biased coin with unknown bias , construct a procedure using only flips of that coin that outputs "heads" or "tails" with probability exactly each.
The move. Flip the coin twice. If the two flips come out the same (HH or TT), discard the pair and flip twice again. If the two flips disagree (HT or TH), stop and output "heads" if the result was HT, or "tails" if it was TH.
Why it's exactly fair. The probability of HT is , and the probability of TH is — the same expression, in either order, because flips are independent. These two probabilities are always equal, for any whatsoever, even though you don't know what is. Conditioning on "the pair disagreed" (i.e., throwing away the HH and TT pairs and only looking at HT/TH), the two remaining outcomes each have probability exactly .
Numerical check. Say (a very biased coin). . . Identical, as promised — the bias cancels because it appears once as and once as in each ordered pair, regardless of which one plays which role.
Two independent flips of a biased coin have the same probability whichever order the two different outcomes occur in — — because multiplication doesn't care about order. Discard the agreeing pairs and condition only on the disagreeing ones, and the bias vanishes without ever needing to be measured.
The number of pairs you need to flip before getting a disagreement is itself random and, if is close to 0 or 1, can be large in expectation — the procedure is exactly fair but not fixed-length. Don't confuse "unbiased" with "fast."
This is a real technique, not just a puzzle: hardware random-number generators built from physically biased sources (thermal noise, jitter) use exactly this von Neumann de-biasing step before the output is trusted for cryptographic or simulation use.
Practice in interviews
Further reading
- von Neumann, Various Techniques Used in Connection with Random Digits (1951)