Suppose we have a coin that lands Heads with some unknown probability p, where
We do not need to know what p is.
We can still generate a perfectly fair 50/50 result.
Let
Because the two flips are independent:
and
But multiplication is commutative:
Therefore,
So whenever we get one of the two usable outcomes HT or TH, they are equally likely.
| Pair | Probability | Action |
|---|---|---|
| HH | p² | Discard |
| HT | p(1-p) | Output Heads |
| TH | (1-p)p | Output Tails |
| TT | (1-p)² | Discard |
Given that the two flips are different, the only possibilities are HT and TH.
Similarly,
Therefore the final output is a perfectly fair 50/50 coin.
Suppose the original coin is extremely biased:
Then:
Even though Heads itself occurs 80% of the time, the patterns HT and TH occur with exactly the same probability.
while true:
flip coin twice
if result == HT:
return Heads
if result == TH:
return Tails
# HH or TT
# throw them away and repeat
Don't try to make a single biased flip fair.
Instead, look for two events that are guaranteed to have equal probability.
The two sequences
contain exactly one Head and one Tail, just in opposite orders.
Therefore both have probability
and we can use them as our two equally likely outcomes.
The flips must be independent and must use the same fixed probability
p each time.
Also, if p = 0 or p = 1,
the method cannot work because the coin never produces both Heads and Tails.
This method is known as the von Neumann extractor.