Skip to content

Instantly share code, notes, and snippets.

@zhibirc
Last active September 7, 2021 18:40
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 zhibirc/929b36329553d575fc18ee436e8e3d17 to your computer and use it in GitHub Desktop.
Save zhibirc/929b36329553d575fc18ee436e8e3d17 to your computer and use it in GitHub Desktop.
Basic password generator.
/**
* Basic password generator.
* Alphabet: digits, English letters in both cases, and special characters.
*
* @param {number[]} range - list of two numeric values "from" and "to" which are UTF code points
* @param {number} length - password length, small values aren't recommended for security reasons
*
* @return {Generator<string, void, *>}
*/
function* generatePassword ( range = [33, 126], length = 20 ) {
while ( 1 ) yield String.fromCodePoint(...Array.from({length}, _ => ~~(range[0] + Math.random() * (range[1] - range[0] + 1))));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment