Skip to content

Instantly share code, notes, and snippets.

@nickodell
Created December 3, 2012 04:34
Show Gist options
  • Save nickodell/4192717 to your computer and use it in GitHub Desktop.
Save nickodell/4192717 to your computer and use it in GitHub Desktop.
import random
def simulation(x):
subjects = 0
trials = 0
while True:
trials += 1
if random.random() < 0.30:
#Runs following code with 30% chance
subjects += 1
if subjects >= 3:
return trials
def average(l):
return sum(l)/float(len(l))
print average(map(simulation, xrange(5000000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment