Re: How to solve this random integer generation problem?



Jia Lin wrote:
Question:

Given a program which can generate one of {1, 2, 3, 4, 5} randomly.
How can we get another generator which can generate one of
{1,2,3,4,5,6,7} randomly?

Generate two values, x and y. Let z = floor[(5x+y-3)/3].
If z > 7 then try again. Otherwise return z.
(There are many such schemes.)

.