Suppose you have a function (or a magic ball) that is capable of producing a totally random integer between 1 and 5 (inclusive).
Using this, how would you generate a random number (also an integer) between 1 and 7 (inclusive)? (Note that the for the number to be random, all integers between 1 and 7 must have an equal chance of being generated)
Assume that using your 15 generator is pretty timeconsuming, so you want to minimize the number of times you are going to use it.
(In reply to
re: solution by Gamer)
My assumption was that this random number generator (of integers between 1 and 7) would be called several times, not just once. I see that that's not stated in the problem, but I guess I just didn't (don't) see a need for just one random number, but rather some stochastic trials that need integers from 1  7.
But yes, if you need only one random number, choosing just two integers from 15 and using fl's techniques would be superior.

Posted by Charlie
on 20030630 15:14:41 