My first instinct was to just call the function a bunch of times and map ranges, which is completely wrong because you can't fix bias that way.
Use the von Neumann extractor to generate unbiased bits from pairs of biased coin flips, then combine bits to produce a uniform integer from 0 to 6. Discuss the expected number of calls, which is 1/(p(1-p)) per unbiased bit, and thus 3/(p(1-p)) for three bits, but note that rejection sampling can reduce calls.
Pro tip: Mention that the expected number of calls is minimized when p=0.5, but the algorithm works for any p in (0,1). Also, highlight that the method is optimal in terms of entropy extraction.
Recognize that the biased coin produces independent bits with unknown bias, and we need to generate uniform integers 0-6 (7 outcomes) using only these bits.
Use the von Neumann trick: flip the coin twice; if outcomes are (0,1) output 0, if (1,0) output 1, otherwise discard and repeat. This yields a fair bit.
Generate three unbiased bits to form a number from 0 to 7. If the number is 7, reject and retry; otherwise return the number (0-6).
Each unbiased bit requires an expected 1/(p(1-p)) pairs of flips, i.e., 2/(p(1-p)) calls. For three bits, expected calls = 6/(p(1-p)). However, rejection of 7 adds a factor of 8/7, so total expected calls = (48/7)/(p(1-p)).
Mention that the expected number of calls can be reduced by using more efficient extraction methods (e.g., generating multiple unbiased bits per pair) or by using a different rejection scheme, but the von Neumann method is simple and optimal in terms of entropy.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.