Created
April 19, 2023 12:28
-
-
Save HananoshikaYomaru/ac547c111ab309548ba6c6c284471a1e to your computer and use it in GitHub Desktop.
getRandomString.ts
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
function generateRandomString(length) { | |
let result = ""; | |
const characters = | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
for (let i = 0; i < length; i++) { | |
result += characters.charAt(Math.floor(Math.random() * characters.length)); | |
} | |
return result; | |
} | |
console.log(generateRandomString(10)); // Output: "xY7jKpLm2T" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment