Created
December 3, 2012 04:34
-
-
Save nickodell/4192717 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
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