Skip to content

Instantly share code, notes, and snippets.

@louicoder
Created December 15, 2022 13:10
Show Gist options
  • Save louicoder/ec6cf41aa3c56d2dca9f03cc244587bf to your computer and use it in GitHub Desktop.
Save louicoder/ec6cf41aa3c56d2dca9f03cc244587bf to your computer and use it in GitHub Desktop.
generate random with of specified length
export const generateString = (length = 10) => {
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";
// const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment