1

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?

xri
  • 111
  • This is essentially the same problem as here: http://math.stackexchange.com/questions/2029880/generating-a-number-using-a-coin/2029949 – Dominik Dec 15 '16 at 09:51
  • Beware that adding three of these random numbers (-2) will not yield a uniform distribution. –  Dec 15 '16 at 09:57

1 Answers1

1

For convenience, shift the ranges to [0,9] and [0,29].

Draw a first number A. Draw a second one, B; if 9, draw again until not 9.

Compute 3.A + B/3.


The reason to reject 9 is to ensure that B/3 is uniform with probabilities 1/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 by 4 instead of 3.

Initialize R
Loop
    Draw A
    Draw B
    Output 3.A + (B+R) / 4
    Keep R = (B+R) % 4
  • Interesting! Thanks Yves Daoust. I'm processing it - will let you know if I have any follow-on questions. – xri Dec 15 '16 at 09:58