Given a function rand() that returns 0 in probability of 0.5 and 1 in 0.5, write a function that generates a number between 0 - n-1 in uniform distribution. that is, for every x in {0,...,n-1} , P(random() == x) = 1/n.
Sigiloso
you use rand2() given function log(n) times. if the N =20. in binary in 10100 means you use rand2() 5 times, for every bit. if your number ig greater then 20, you have to start again. (modulu can harm the P(random() == x) = 1/n. )