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()
returns
0
with probability
p
and
1
with probability
1-p
, where
p
is unknown and may be any value in
(0,1)
.
Design and implement:
int getRandom06Uniform()
that returns an integer in
[0,6]
with
exactly uniform
probability
1/7
.
Constraints/notes:
getRandom01Biased()
multiple times.
p
in
(0,1)
.