Skip to content

Instantly share code, notes, and snippets.

@joejag
Last active October 5, 2022 23:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
The birthday paradox. If you have 23 people, there's a 50% chance they share a birthday
from collections import Counter
from random import randrange
results = []
# Run this 10k times
for _ in range(0, 10000):
# Give me 23 random birth dates given 365 days in a year
birthdays = [randrange(365) for _ in range(23)]
# Check for any overlap
results.append(len(birthdays) != len(set(birthdays)))
# There's over a 50% chance of an overlap when there are 23 people
print(Counter(results))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment