Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
hash collision probability test
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
You can’t perform that action at this time.