Skip to content

Instantly share code, notes, and snippets.

@fedeghe
Created March 22, 2024 20:08
Show Gist options
  • Save fedeghe/9440c2eae0e4edd414abe629d163f315 to your computer and use it in GitHub Desktop.
Save fedeghe/9440c2eae0e4edd414abe629d163f315 to your computer and use it in GitHub Desktop.
Password generaator
const genPassword = (i,u,l) => {
function* getPassword(i, u, l) {
function* gen(start, end, len) {
while(len--)
yield start + ~~(Math.random() * (end-start));
}
yield* gen(48, 57, i);// 0..9
yield* gen(65, 90, u);// A..Z
yield* gen(97, 122, l);// a..z
}
return [...getPassword(i,u,l)]
.sort(() => Math.random()>.5 ? 1 : -1)
.map(c => String.fromCharCode(c)).join('');
}
/*
* const str = genPassword(10, 10, 10)
* console.log(str)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment