Created
May 28, 2020 10:26
-
-
Save Aschen/e5195f2742a7bc8fd391109d20176581 to your computer and use it in GitHub Desktop.
Generate random 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
const CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; | |
function uniqueId (size) { | |
let id = ''; | |
for (let idx = size; idx--;) { | |
id += CHARSET[(Math.random() * CHARSET.length | 0)]; | |
} | |
return id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment