Skip to content

Instantly share code, notes, and snippets.

@amenayach
Created December 6, 2019 08:22
Show Gist options
  • Save amenayach/4b43e8fa13be673d6df518ec96614c82 to your computer and use it in GitHub Desktop.
Save amenayach/4b43e8fa13be673d6df518ec96614c82 to your computer and use it in GitHub Desktop.
Generates random alpha numeric string
function getRandomChar(isChar) {
return parseInt(Math.random() * 100) % (isChar === true ? 26 : 10);
}
function getRandomString(length) {
return [...new Array(length)]
.map((x, i) =>
i % 2 === 0 ?
String.fromCharCode(65 + getRandomChar(true)).toString() :
getRandomChar(false).toString())
.join('').toLowerCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment