Quant Memo
Coding/●●●●●

Uniform integer from a fair coin

You can flip a fair coin as often as you like and nothing else.

Return a uniform integer in {0,1,,n1}\{0, 1, \dots, n-1\}. Prove uniformity, give the expected number of flips, and explain why the naive "gather bits, take mod nn" is biased.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions