Last active
January 11, 2021 00:25
-
-
Save max-pub/d7524fcfe38a20c12fef to your computer and use it in GitHub Desktop.
generate a unique ID
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
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