A particular random number generator returns positive integer n with probability 1/(2^n). (ie '1' with probability 1/2, '2' with probability 1/4, '3' with probability 1/8, etc.)
Using this random number generator, write an algorithm which chooses a random integer from 1 to 37 with equal probability.
(In reply to
re(3): solution - Charlie? by Charlie)
Charlie,
I asked about the 2nd half of my first posting. You described the 1st half which is "particularly inefficient".
Come to think of it, what is the average number of calls per 1-37 number from Brian's solution as well?
Edited on June 16, 2004, 1:18 am
|
Posted by Thalamus
on 2004-06-16 01:04:11 |