Last active
December 30, 2015 04:09
-
-
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
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
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