Last active
November 28, 2019 21:16
-
-
Save gilbarbara/559160eee86570fac61084be2af44f03 to your computer and use it in GitHub Desktop.
Generate a random alphanumeric string
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
function randomID(size = 6) { | |
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
let text = ''; | |
for (let i = 0; i < size; i++) { | |
text += possible.charAt(Math.floor(Math.random() * possible.length)); | |
} | |
return text; | |
} | |
function uniqueID(size = 10) { | |
return [...Array(size)].map(() => (~~(Math.random() * 36)).toString(36)).join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment