Created
September 12, 2019 14:42
-
-
Save gkucmierz/be183bf2dfd58e97d0b3d16a79d8a1a0 to your computer and use it in GitHub Desktop.
random word, password generator
This file contains hidden or 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 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