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 1-5 generator is pretty time-consuming, so you want to minimize the number of times you are going to use it.
(In reply to
solution by Charlie)
Sorry if I missed something, but when you use really high numbers (like 5^7), wouldn't that need 7 attempts to find a random number? This means you are already up to 7 uses at minimum.
|
Posted by Gamer
on 2003-06-30 13:26:10 |