- Choose some fairly large even integer n.
- Create a table “t” containing two integers.
- Loop over $i=1,ldots,n$ sampling $x=rand()$ for each $i$. When $i$ is even increment $t[i]$ and when odd increment $t[1-i]$.
- Return $0$ if $t[0]geq t[1]$ and vice versa.
Now the expected value for $t[0]=t[1]=n/2$, so this should give a value very close to the uniform distribution. The only problem is that the set of outcomes in (4) is biased towards $0$, so for any fixed $n$, we do not get a uniform distribution, although we do get it in the limit. There has to be a way to get $n$ to depend on some random value to balance it out, but I can’t figure out how. Anyone have any other ideas how to approach this? The key in the problem was that we do not know $p$.
Asked By : JT1
Answered By : Yuval Filmus
- Repeatedly sample two biased samples $r_1,r_2$ until $r_1 neq r_2$.
- Return $r_1$.
Conditioned on $r_1 neq r_2$, the two outcomes $(r_1,r_2)=(0,1)$ and $(r_1,r_2)=(1,0)$ have the same probability, and so the result is an unbiased bit. How efficient is this generator? The probability that $r_1 neq r_2$ is $2p(1-p)$, and so on average you will need $1/(2p(1-p))$ samples per bit. Compare that to the optimal extractor given by Shannon’s source coding theorem: extracting $n$ bits should take $n/H(p) + o(n)$ samples with high probability (when $p$ is known).
The plot shows that the von Neumann algorithm is reasonably good but not optimal.
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/35218