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.
An ab"normal" solution.
Here's a different idea which is neither elegant, efficient or exact, but could be made as accurate as desired, at least in theory. [For the real solution, see Charlie's]
The sum or average of a series of random numbers approaches a Normal Distribution, no matter what the probability distribution of the underlying random variable. So, one could run the RNG "N" times, compute the sum (or average). The expected value of the RNG is 2, so the mean of the new random number would be 2*N, (for the sum). One could calculate the expected standard deviation, then divide the Normal Curve into 37 "bins" of equal area under the curve.
The larger N is, the closer the sum of the N numbers would be to a Normal Distribution; whatever degree of precision is desired, it would be possible to pick N large enough to achieve it. But since the underlying random variable has an infinite tail to the right, it might take a very large N to get the desired level of precision; so it might be better to first convert the RNG to a Binomial (as noted in Thalamus' answer), then sum N of those. I suspect you'd have to run the RNG 1000 times to get one number this way.
Edited on June 9, 2004, 10:13 am

Posted by Larry
on 20040608 23:58:01 