Suppose I have a random number generator that can produce a uniform distribution of natural numbers in the range $[1, 10]$. So there are 10 possible values the generator can produce.
Suppose I would like to generate natural numbers with a uniform distribution spanning $[1, 30]$. Is there a way to do that with my existing generator?
For convenience, shift the ranges to
[0,9]and[0,29].Draw a first number
A. Draw a second one,B; if9, draw again until not9.Compute
3.A + B/3.The reason to reject
9is to ensure thatB/3is uniform with probabilities1/3.If I am right, you can also keep the remainder from one drawing to the next, add it to
B(giving a uniform number in[0,11]) and divide by4instead of3.