Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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