Skip to content

Instantly share code, notes, and snippets.

@AnthonyNixon
Created April 18, 2017 05:10
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 AnthonyNixon/4745e716866cb3f3b1ac968f16a564c1 to your computer and use it in GitHub Desktop.
Save AnthonyNixon/4745e716866cb3f3b1ac968f16a564c1 to your computer and use it in GitHub Desktop.
Same Birthday Script
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