Generate uniform 0–6 from biased coin
LinkedInMachine Learning Engineer · OnsiteLast updated
This question evaluates understanding of randomized algorithms, probability theory, and techniques for extracting uniform randomness from a biased source.
You are given a function:
int getRandom01Biased()returns0with probabilitypand1with probability1-p, wherepis unknown and may be any value in(0,1).
Design and implement:
int getRandom06Uniform()that returns an integer in[0,6]with exactly uniform probability1/7.
Constraints/notes:
- You may call
getRandom01Biased()multiple times. - The algorithm must be correct for any
pin(0,1). - Discuss expected number of calls (at least at a high level).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.