Created
March 22, 2024 20:08
-
-
Save fedeghe/9440c2eae0e4edd414abe629d163f315 to your computer and use it in GitHub Desktop.
Password generaator
This file contains 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 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