Skip to content

Instantly share code, notes, and snippets.

@vijaykramesh
Last active December 30, 2015 04:09
Show Gist options
  • Save vijaykramesh/7774378 to your computer and use it in GitHub Desktop.
Save vijaykramesh/7774378 to your computer and use it in GitHub Desktop.
partition an id of some sort into the unit interval, using md5 hexdigest
var crypto = require('crypto');
var salt = "some_salt";
function place_in_interval(id) {
var m = crypto.createHash('md5');
m.update(salt + ":" + id)
var key = m.digest('hex');
return parseInt(key,16) / Math.pow(16,key.length);
}
place_in_interval(10);
place_in_interval("Asdf1234");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment