Last active
November 11, 2021 11:27
-
-
Save samcorcos/e65a0f5a5d641dd3a6b5f513b6a911f8 to your computer and use it in GitHub Desktop.
Algorithm for calculating hash collision probability
This file contains hidden or 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
const calculate = (n, k) => { | |
const exponent = (-k * (k - 1)) / (2 * n) | |
return 1 - Math.E ** exponent | |
} | |
// where `n` is the number of possible unique hashes | |
// where `k` is the number of values created | |
// calculate(100000, 25) => 0.0029955044966269995 aka 0.29% chance of collision |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment