Skip to content

Instantly share code, notes, and snippets.

@joejag
Last active October 5, 2022 23:26
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 joejag/6fe8963a9945045b5f6a5627d8e22568 to your computer and use it in GitHub Desktop.
Save joejag/6fe8963a9945045b5f6a5627d8e22568 to your computer and use it in GitHub Desktop.
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