Skip to content

Instantly share code, notes, and snippets.

@FlameWolf
Last active May 26, 2023 13:13
Show Gist options
  • Save FlameWolf/135bb4bae8518a45a7f5a2b6344bbbf3 to your computer and use it in GitHub Desktop.
Save FlameWolf/135bb4bae8518a45a7f5a2b6344bbbf3 to your computer and use it in GitHub Desktop.
Generate random ID string
const getRandomIdString = (len = 32) => {
let retVal = "";
for (let i = 0; i < len; i++) {
const randVal = Math.random();
retVal += String.fromCharCode((randVal < 0.5 ? ((randVal * 26) + 65) : ((randVal * 10) + 48)) >> 0);
}
return retVal;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment