Created
August 14, 2018 14:23
-
-
Save esquinas/6727e725da943d8a3730b1571dcdfced to your computer and use it in GitHub Desktop.
Calculate percentage probability of birthday collisions (Birthday paradox) in Ruby
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
def prob_of_birthday_collision(people = 23.0, days = 365.25) | |
e = Math::E | |
k = people.to_f() | |
n = days.to_f() | |
return 100.0 * (1.0 - e**((-k * (k - 1.0)) / (2.0 * n))) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment