I am given a uniform integer random number generator $\sim U_3(1,3)$ (inclusive). I would like to generate integers $\sim U_5(1,5)$ (inclusive) using $U_3$. What is the best way to do this?
This simplest approach I can think of is to sample twice from $U_3$ and then use rejection sampling. i.e., sampling twice from $U_3$ gives us 9 possible combinations. We can assign the first 5 combinations to 1,2,3,4,5, and reject the last 4 combinations.
This approach expects to sample from $U_3$ $\frac{9}{5} * 2 = 18/5 = 3.6$ times.
Another approach could be to sample three times from $U_3$. This gives us a sample space of $27$ possible combinations. We can make use of $25$ of these combinations and reject the last 2. This approach expects to use $U_3$ $\frac{27}{25} * 3.24$ times. But this approach would be a little more tedious to write out since we have a lot more combinations than the first, but the expected number of sampling from $U_3$ is better than the first.
Are there other, perhaps better, approaches to doing this?
a = 0.u1u2u3...
Then convert this number to base 5:0.v1v2v3...
. The numbers v1, v2, v3, ... (which are 0-4 since it's base 5) is your U5 – ypercubeᵀᴹ Sep 07 '20 at 17:21