Skip to content

Instantly share code, notes, and snippets.

@esquinas
Created August 14, 2018 14:23
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 esquinas/6727e725da943d8a3730b1571dcdfced to your computer and use it in GitHub Desktop.
Save esquinas/6727e725da943d8a3730b1571dcdfced to your computer and use it in GitHub Desktop.
Calculate percentage probability of birthday collisions (Birthday paradox) in Ruby
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