Last active
April 23, 2017 10:57
-
-
Save madcampos/b21c975b7e57fb2128cf2f1af33746c4 to your computer and use it in GitHub Desktop.
Random string
This file contains hidden or 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
| //Generates a alphanumeric random string given the length. | |
| //Tweet version: let randomString=(l)=>`${l?(Math.random()*Math.pow(10,18)).toString(36):''}${l>10?randomString(l-10):''}`.substr(0,l); | |
| function randomString(length){ | |
| let str = ''; | |
| if (length) { | |
| str += (Math.random() * Math.pow(10, 18)).toString(36); | |
| } | |
| if (length > 10) { | |
| str = randomString(length - 10); | |
| } | |
| return str.substr(0, length); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment