9 ms·
Unbiasing a coin is easy (the Von Neuman technique): toss it twice, if the results are different then output the first toss. If the results are the same, forget
by jknz 9y ago
Unbiasing a coin is easy (the Von Neuman technique): toss it twice, if the results are different then output the first toss. If the results are the same, forget both and start again.
You can use this technique to unbias a 4-die or 8-die by throwing a coin multiple times (apply the above technique for each digit in base 2).
To produce a fair 6-die from a biased coin, the following should work.
- Using the Von-Neumann technique, creates 3 independent unbiased coin X, Y, Z. Then X= 1 + X + 2Y + 2Z is uniform in {1,...,8}, we basically randomize each digit in base 2.
- Finally, throw the unbiased 8-die until you obtain a number different than 7,8. The result is unbiased in {1,...6}.
import numpy as np
def biased_coin():
return np.random.choice([0,1], p=[0.1,0.9])
def unbiased_coin():
a = biased_coin()
b = biased_coin()
if a != b:
return a
else:
return unbiased_coin()
def unbiased_eight():
return 1 + unbiased_coin() + 2*unbiased_coin() +4*unbiased_coin()
def unbiased_six():
d = unbiased_eight()
if d < 7:
return d
else:
return unbiased_six()
np.bincount([unbiased_six() for i in range(6000)])
Edit: there was a mistake in the previous version of the comment because the digits in base 2 were not be independent. The last version is correct, I believe :)
- deleted 9y ago[deleted]