已知一个函数f可以得到1-5间的随机数,问怎么得到1-7的随机数
I suppose what you mean is given a random number generator that generates 1-
5 with equal prob. (1/5), create another random generator that generates 1-7
with equal prob (1/7).
Assuming the 1-5 generator generates i.i.d. numbers. We will put two numbers
in one group, e.g. from
1, 2, 5, 3, 1, 4, ...
we get
(1, 2), (5, 3), (1, 4), ...
We will have 25 different pairs with equal prob (1/25). We only pick 14
pairs as valid pairs, discard other 11 pairs. We call them pair #1, #2, ...,
#14. When we get pair #1or #2, we output number 1, ... if we get pair #13
or #14, we output 7.