Skip to main content
3 of 5
typo (two more flips, not three, as pointed out in the comment)
David Richerby
  • 82.2k
  • 26
  • 144
  • 238

An alternative to rejection sampling (as described in FrankW's answer) is to use a scaling algorithm, that takes into account an answer of [7,8] as if it was another coin flipping.

There is a very detailed explanation at mathforum.org, including the algorithm (its NextBit() would be flipping your fair coin).

The case for throwing a dice with a fair coin (sampling 2 → 6) is easier than the generic algorithm. You just take a failure (7 or 8) as another coin input and perform two more flips.

Ángel
  • 203
  • 1
  • 5