Created
November 4, 2012 06:12
-
-
Save anonymous/4010541 to your computer and use it in GitHub Desktop.
Secret Santa Sim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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