Skip to content

Instantly share code, notes, and snippets.

Created November 4, 2012 06:12
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 anonymous/4010541 to your computer and use it in GitHub Desktop.
Save anonymous/4010541 to your computer and use it in GitHub Desktop.
Secret Santa Sim
import random
def simlottery(numsim, N):
success = 0
for i in range(numsim):
success += choicesim(N)
return float(success) / numsim
def choicesim(N):
lottery = range(N)
for j in range(N-1):
pick = random.choice(lottery)
while pick == j:
pick = random.choice(lottery)
lottery.remove(pick)
if lottery[0] == N - 1:
return 1
else:
return 0
print "N = 3: " + str(simlottery(500000, 3))
print "N = 4: " + str(simlottery(500000, 4))
print "N = 5: " + str(simlottery(500000, 5))
print "N = 6: " + str(simlottery(500000, 6))
print "N = 7: " + str(simlottery(500000, 7))
print "N = 8: " + str(simlottery(500000, 8))
print "N = 9: " + str(simlottery(500000, 9))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment