Created
December 6, 2019 08:22
-
-
Save amenayach/4b43e8fa13be673d6df518ec96614c82 to your computer and use it in GitHub Desktop.
Generates random alpha numeric string
This file contains 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 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