Last active
March 24, 2023 14:01
-
-
Save djhouseknecht/257c1590e00adbcd47188ffae884e356 to your computer and use it in GitHub Desktop.
Generate a string of random characters
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 chars = [ | |
'a', 'A', | |
'b', 'B', | |
'c', 'C', | |
'd', 'D', | |
'e', 'E', | |
'f', 'F', | |
'g', 'G', | |
'h', 'H', | |
'i', 'I', | |
'j', 'J', | |
'k', 'K', | |
'l', 'L', | |
'm', 'M', | |
'n', 'N', | |
'o', 'O', | |
'p', 'P', | |
'q', 'Q', | |
'r', 'R', | |
's', 'S', | |
't', 'T', | |
'u', 'U', | |
'v', 'V', | |
'w', 'W', | |
'x', 'X', | |
'y', 'Y', | |
'z', 'Z', | |
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9' | |
]; | |
function getRandomString (length) { | |
let str = ''; | |
for (let i = 0; i < length; i++) { | |
const index = Math.floor(Math.random() * chars.length); | |
str += chars[index]; | |
} | |
return str; | |
} | |
function runLoop(count, len = 5) { | |
const results = []; | |
for (let c = 0; c < count; c++) { | |
results.push(getRandomString(len)); | |
} | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment