Skip to content

Instantly share code, notes, and snippets.

@max-pub
Last active January 11, 2021 00:25
Show Gist options
  • Save max-pub/d7524fcfe38a20c12fef to your computer and use it in GitHub Desktop.
Save max-pub/d7524fcfe38a20c12fef to your computer and use it in GitHub Desktop.
generate a unique ID
uniqueID = (length=6, n=true, lc=true, uc=true) => { // 62^6 = 50 Billion
let chars = '';
if (n) chars += '1234567890';
if (lc) chars += 'abcdefghijklmnopqrstuvwxyz';
if (uc) chars += 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let ID = '';
for (let i = 0; i < length; i++)
ID += chars[Math.floor((Math.random() * chars.length))];
return ID;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment