Skip to content

Instantly share code, notes, and snippets.

@christophchamp
Created March 11, 2017 10:47
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 christophchamp/395300e6af0f89d04b18d25d798778dc to your computer and use it in GitHub Desktop.
Save christophchamp/395300e6af0f89d04b18d25d798778dc to your computer and use it in GitHub Desktop.
#!/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