Skip to content

Instantly share code, notes, and snippets.

@vanrez-nez
Last active April 28, 2016 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanrez-nez/ace2302d007f577e3550 to your computer and use it in GitHub Desktop.
Save vanrez-nez/ace2302d007f577e3550 to your computer and use it in GitHub Desktop.
Generate string ID's of a fixed length
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