Last active
December 10, 2018 03:11
-
-
Save brookjordan/0f9adff2051b83d5e707a3286d4f19f2 to your computer and use it in GitHub Desktop.
Create a random string using characters from the base 64 allowed chars
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 randomString(length = 16) { | |
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/'; | |
const charCount = chars.length; | |
let str = ''; | |
while (length-- > 0) { | |
str += chars[Math.floor(Math.random() * charCount)]; | |
} | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment