Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Created September 12, 2019 14:42
Show Gist options
  • Save gkucmierz/be183bf2dfd58e97d0b3d16a79d8a1a0 to your computer and use it in GitHub Desktop.
Save gkucmierz/be183bf2dfd58e97d0b3d16a79d8a1a0 to your computer and use it in GitHub Desktop.
random word, password generator
const randomWord = (len = 16, up = true, low = true, digits = true, special = '') => {
const chars = [special];
up && chars.push('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
low && chars.push('abcdefghijklmnopqrstuvwxyz');
digits && chars.push('0123456789');
const str = chars.join``;
const word = [];
for (let i = 0; i < len; ++i) {
word[i] = str[Math.round(Math.random() * str.length) % str.length];
}
return word.join``;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment