Last active
September 29, 2016 12:10
-
-
Save iSkore/86c70bd803056ede6e45bc2c8bd2c2f1 to your computer and use it in GitHub Desktop.
Super fast random string generator
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
const rand = () => { | |
const a = [ | |
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', | |
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', | |
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', | |
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', | |
'w', 'x', 'y', 'z', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 | |
]; | |
let i = -1; | |
while ( ++i < 62 ) { | |
const | |
r = i + Math.floor( Math.random() * ( 61 - i + 1 ) ), | |
v = a[ r ]; | |
a[ r ] = a[ i ]; | |
a[ i ] = v; | |
} | |
return a.join( '' ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment