Last active
June 17, 2024 15:15
-
-
Save lac5/a2223ff9fce397aafcc3176e3bd3662a to your computer and use it in GitHub Desktop.
randomstring.js
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 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