Skip to content

Instantly share code, notes, and snippets.

@igorrs
Created September 19, 2019 15:50
Show Gist options
  • Save igorrs/7155f710d51f5e7a156fd8558113824e to your computer and use it in GitHub Desktop.
Save igorrs/7155f710d51f5e7a156fd8558113824e to your computer and use it in GitHub Desktop.
Probability of collision after generating k random base-32 numbers with x digits
def probability_of_collision(k, x)
total_numbers = 32**x
1 - Math::E**(((k-1)*-k) / (2.0*total_numbers))
end
# Example
probability_of_collision(100000, 8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment