Skip to content

Instantly share code, notes, and snippets.

@HananoshikaYomaru
Created April 19, 2023 12:28
Show Gist options
  • Save HananoshikaYomaru/ac547c111ab309548ba6c6c284471a1e to your computer and use it in GitHub Desktop.
Save HananoshikaYomaru/ac547c111ab309548ba6c6c284471a1e to your computer and use it in GitHub Desktop.
getRandomString.ts
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