Skip to content

Instantly share code, notes, and snippets.

@CamDavidsonPilon
Created November 24, 2013 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CamDavidsonPilon/7633191 to your computer and use it in GitHub Desktop.
Save CamDavidsonPilon/7633191 to your computer and use it in GitHub Desktop.
biased coins to unbiased (heh cheating)
import random
p1 = 0.9
p2 = 0.1
N = 10000
s = 0.0
i = 0
while i < N:
if (random.random() < 0.5): #THIS IS WHERE I CHEAT
#group A, flip C1 first, want to get H1T2
C1 = random.random() < p1
C2 = random.random() < p2
if C2 != C1:
if C1 == True and C2 == False:
s+=1
i+=1
else:
C2 = random.random() < p2
C1 = random.random() < p1
#group B, flip C2 first, want to get H2T1
if C2 != C1:
if C2 == True and C1 == False:
s+=1
i+=1
print i
print s
print s/N
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment