-
-
Save jed/973263 to your computer and use it in GitHub Desktop.
generate a random ID
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
function( | |
a, // the character length of the ID (optional, 32 by default) | |
b // the radix of the ID (optional, 16 by default) | |
){ | |
b = b || 16; // use a default radix of 16 | |
return Array( // return an array | |
a // of the length, if specified, | |
|| 32 // or 32 otherwise, | |
) | |
.join(0) // joined into a string of 0s, | |
.replace( // and then replace | |
/./g, // each one, with | |
function() { | |
return( | |
0| // a rounded | |
Math.random()* // random number between 0 and | |
b // the radix, | |
) | |
.toString(b) // and serialize it into a string. | |
} | |
) | |
} |
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
function(a,b){b=b||16;return Array(a||32).join(0).replace(/0/g,function(){return(0|Math.random()*b).toString(b)})} |
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
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
Version 2, December 2004 | |
Copyright (C) 2011 Jed Schmidt <http://jed.is> | |
Everyone is permitted to copy and distribute verbatim or modified | |
copies of this license document, and changing it is allowed as long | |
as the name is changed. | |
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
0. You just DO WHAT THE FUCK YOU WANT TO. |
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
{ | |
"name": "randomID", | |
"keywords": [ "random", "ID" ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great work!