Skip to content

Instantly share code, notes, and snippets.

@lac5
Last active June 17, 2024 15:15
Show Gist options
  • Save lac5/a2223ff9fce397aafcc3176e3bd3662a to your computer and use it in GitHub Desktop.
Save lac5/a2223ff9fce397aafcc3176e3bd3662a to your computer and use it in GitHub Desktop.
randomstring.js
const letters = 'abcdefghijklmnopqrstuvwxyz'
function randomString(max, min = 1) {
let length = Math.floor(Math.random()*(max+2-min)+min);
let word = '';
while (word.length < length) {
word += letters[Math.floor(Math.random()*letters.length)];
}
return word;
}
exports.randomString = randomString;
if (require.main === module) {
let arg1 = Math.max(process.agrv[2] | 0, 1);
let arg2 = Math.max(process.agrv[3] | 0, 1);
console.log(randomString(arg1, arg2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment