Last active
August 29, 2015 14:25
-
-
Save phiresky/f651244ca61568b9a19a to your computer and use it in GitHub Desktop.
hash collision probability test
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
second = 1; | |
year = 365.25 * 24 * 60 * 60 * second; | |
universe_age = 13.82e9 * year; | |
hash_length = 256; | |
hash_speed = 2500 * 1e6 / second; // fastest GPU from https://en.bitcoin.it/wiki/Non-specialized_hardware_comparison | |
probability_of_asteroid_wiping_out_humans = 1 / (100 * 1e6 * year); // http://www.wired.com/2013/02/asteroid-odds/ | |
// http://preshing.com/20110504/hash-collision-probabilities/ | |
function collision_probability(tries, possibilities) { | |
return -Math.expm1(-tries*(tries-1)/2/possibilities); | |
} | |
hash_collision_probability = collision_probability(universe_age * hash_speed, Math.pow(2,hash_length)) | |
console.log("Hash collision probability if you would have been hashing since the beginning of time: "+hash_collision_probability); | |
if(hash_collision_probability < probability_of_asteroid_wiping_out_humans) { | |
console.log("It's more likely human kind will be wiped out in the next second by an asteroid."); | |
} else { | |
console.log("Your hash function is shit."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment