Created
April 18, 2017 05:10
-
-
Save Niximacco/4745e716866cb3f3b1ac968f16a564c1 to your computer and use it in GitHub Desktop.
Same Birthday Script
This file contains hidden or 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 | |
num_people = 100 | |
num_trials = 10000 | |
for personCount in range(2,num_people+1): | |
trial_success = 0 | |
for trialCount in range(0, num_trials): | |
birthdays = [] | |
for person in range(0, personCount): | |
birthday = random.randint(1,365) | |
if birthday in birthdays: | |
trial_success += 1 | |
break | |
birthdays.append(random.randint(1, 365)) | |
percent_success = (float(trial_success) / float(num_trials)) | |
print str(personCount) + "\t" + str(round(percent_success, 6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment