Created
March 11, 2017 10:47
-
-
Save christophchamp/395300e6af0f89d04b18d25d798778dc to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
from random import randint | |
RANGE = 1000000 | |
def random_guess(RANGE): | |
wins = [] | |
for _ in range(0, RANGE): | |
guess = randint(0, 1) | |
outcome = randint(0, 1) | |
if guess == outcome: | |
wins.append(1) | |
return wins | |
def same_guess(RANGE): | |
wins = [] | |
for _ in range(0, RANGE): | |
outcome = randint(0, 1) | |
if outcome == 1: | |
wins.append(1) | |
return wins | |
guess = random_guess(RANGE) | |
same = same_guess(RANGE) | |
print "guess: %s\tsame: %s" % ( | |
len(guess)/(RANGE * 1.0), | |
len(same)/(RANGE * 1.0)) | |
# Where "guess" is randomly guessing heads or tails and "same" is always choosing heads. | |
# | |
# Sample run: | |
# guess: 0.499779 same: 0.499628 | |
# In other words, no difference. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment