Last active
October 5, 2022 23:26
-
-
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
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
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