Challenge: Smaller to Larger Random Number Generator

Let’s say you have a random number generator RNG3() that uniformly returns from delim{lbrace;}{1, 2, 3}{rbrace;} and you must use it to build RNG7() that uniformly returns from delim{lbrace;}{1, 2, 3, 4, 5, 6, 7}{rbrace;}. How might you do it?

Hint
It’s not a variant on RNG3() + RNG3(), as that yields a bell curve.
My Answer
Create a 3*3 matrix with uniform values delim{lbrace;}{1, 2, 3, 4, 5, 6, 7}{rbrace;} as follows:33

do {
    RNG7 = M[RNG3()][RNG3()];
} while (RNG7 == 0);

Leave a Reply

Your email address will not be published. Required fields are marked *