Created
June 19, 2021 11:30
-
-
Save mudssrali/50ea580dfb7e6f2ac5916664d58d9b3c to your computer and use it in GitHub Desktop.
Generate a random string of variable length
This file contains hidden or 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 generateRandomString = (stringLength) => { | |
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' | |
const charactersLength = characters.length | |
let randomString = '' | |
for (let i = 0; i < Math.abs(stringLength); i++) { | |
randomString += characters.charAt(Math.floor(Math.random() * charactersLength)) | |
} | |
return randomString | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment