Last active
October 1, 2021 12:07
-
-
Save alexalannunes/57a056db8bedced2acc142a1da7c6d02 to your computer and use it in GitHub Desktop.
id generator with while
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(size = 21) { | |
let urlAlphabet = "sys_abcdefghijklmnopqrstuvwxyz0123456789"; | |
const length = urlAlphabet.length; | |
let id = ""; | |
// A compact alternative for `for (var i = 0; i < step; i++)`. | |
let i = size; | |
while (i--) { | |
// `| 0` is more compact and faster than `Math.floor()`. | |
id += urlAlphabet[(Math.random() * length) | 0]; | |
} | |
return id; | |
}; | |
a(210); | |
/* | |
'xrsvkqe8r95py7zggvu4wtybow0eob4r222k9ysz2_5sms4sw_mw0my5wbyugm78sorrx1sd_hxyrzf8lusjk9v887mar_ai17u9vpmq55l_sgwf7bao6osdhttsrhuys25yegsh4rxmf2jln0um_dpmhudi8e7brtqarp8wkrdq6v26o23upso0uq72w11g9snt9e6fcngmem5nzp' | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment