I knew the Von Neumann trick from somewhere in the back of my brain, pairs of calls where 01 maps to 0 and 10 maps to 1 and you just retry on 00 or 11.
Use rejection sampling to generate unbiased random bits from the biased function, then combine bits to form a uniform integer in a range that is a multiple of 7, rejecting out-of-range values. This ensures each integer from 0 to 6 has equal probability.
Pro tip: Mention that rejection sampling is efficient because the expected number of calls is constant, and discuss how to optimize by using as many bits as possible per attempt to minimize waste.
Use the biased function to produce fair bits by calling it twice and mapping (0,1) to 0 and (1,0) to 1, ignoring (0,0) and (1,1).
Collect enough fair bits to represent a range that is a multiple of 7, such as 3 bits (0-7), and interpret them as an integer.
If the generated integer is 7, reject it and repeat the process; otherwise, return the integer (0-6).
Explain that each fair bit requires an expected 2 calls to the biased function, and the rejection probability is 1/8, so the expected number of calls is constant.
Mention that using more bits per attempt (e.g., 6 bits for 0-63) can reduce the rejection rate, but the simple 3-bit method is sufficient and easy to implement.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.