Skip to content

Instantly share code, notes, and snippets.

@SCJLabs
Last active August 29, 2015 14:22
Show Gist options
  • Save SCJLabs/53dd7057f1eed85943b5 to your computer and use it in GitHub Desktop.
Save SCJLabs/53dd7057f1eed85943b5 to your computer and use it in GitHub Desktop.
Generate a unique ID number. You can specify how many characters you want the length to be
//Generate a unique ID number
function generateUniqueID() {
var length = 10;
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
return result;
}
//Usage: declare variable then assign it the value of the newly generated ID
var unique_id = generateUniqueID();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment