Last active
April 28, 2016 23:23
-
-
Save vanrez-nez/ace2302d007f577e3550 to your computer and use it in GitHub Desktop.
Generate string ID's of a fixed length
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
function generateID() { | |
return ("000000" + (Math.random()*Math.pow(36,6) << 0).toString(36)).slice(-6)); | |
} | |
function generateIDFromStr() { | |
var seed = str.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0); | |
return ( "000000" + ( seed << 0 ).toString( 36 ) ).slice( -6 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment