Optimal rolling of fair dice using fair coins
Mark Huber, Danny Vargas
TL;DR
The paper tackles efficient sampling from a finite uniform distribution using fair coin flips within the Knuth–Yao framework. It presents a randomness-recycling implementation that tracks a state $(X,m)$ with $[X|m] \sim \mathrm{d}m$ and doubles $m$ until at least $n$, then either accepts when $X \le n$ or reduces to a smaller subproblem via $(X-n,m-n)$. The authors prove correctness and optimality of the resulting DDG, derive the bound $\mathbb{E}[N_n] \le \lceil \log_2(n) \rceil + 1$, and extend the method to general discrete distributions using a bit-decomposition of probabilities. The approach yields a simple, memory-efficient, near-optimal sampler for fair dice and general discrete distributions, with potential applicability to loaded dice when combined with binary-probability representations.
Abstract
In 1976, Knuth and Yao presented an algorithm for sampling from a finite distribution using flips of a fair coin that on average used the optimal number of flips. Here we show how to easily run their algorithm for the special case of rolling a fair die that uses memory linear in the input. Analysis of this algorithm yields a bound on the average number of coin flips needed that is slightly better than the original Knuth-Yao bound. This can then be extended to discrete distributions in a near optimal number of flips again using memory linear in the input.
