Skip to content

Instantly share code, notes, and snippets.

@jColeChanged
Last active December 18, 2015 21:29
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 jColeChanged/5847458 to your computer and use it in GitHub Desktop.
Save jColeChanged/5847458 to your computer and use it in GitHub Desktop.
import random
def initialize_urn():
reds = ["red" for i in range(50)]
blacks = ["black" for i in range(50)]
return reds + blacks
def get_pair(urn):
choice_1 = random.choice(urn)
urn.remove(choice_1)
choice_2 = random.choice(urn)
urn.remove(choice_2)
return [choice_1, choice_2]
def approximate():
num_trials = 10000
num_draws = 50
trial_results = []
for trial in range(num_trials):
num_both = 0
urn = initialize_urn()
for draw in range(num_draws):
pair = get_pair(urn)
if "red" in pair and "black" in pair:
num_both += 1
trial_results.append(float(num_both))
average_both = sum(trial_results) / num_trials
print average_both
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment