Skip to content

Instantly share code, notes, and snippets.

@brookjordan
Last active December 10, 2018 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brookjordan/0f9adff2051b83d5e707a3286d4f19f2 to your computer and use it in GitHub Desktop.
Save brookjordan/0f9adff2051b83d5e707a3286d4f19f2 to your computer and use it in GitHub Desktop.
Create a random string using characters from the base 64 allowed chars
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