Question: Suppose you are given a subroutine Rand() that when called, produces a uniformly random bit. Suppose you need to generate a uniformly random integer in
Suppose you are given a subroutine Rand() that when called, produces a uniformly random bit. Suppose you need to generate a uniformly random integer in the range from 0 to 29 (inclusive). Consider an algorithm that call Rand() 5 times and interprets the results as a binary expansion of a number between 0 and 31. If this number is < 30 it is returned as the result, otherwise it is discarded and Rand() is called 5 more times. This process is repeated as many times as necessary to obtain a number between 0 and 29. What is the expected running time of this algorithm in terms of iterations? Now suppose you would prefer an algorithm that is guaranteed to terminate after a fixed constant number of calls to Rand() and still returns a perfectly uniform distribution on 0 to 29. Is this possible? Explain why or why not.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
