Skip to content

Instantly share code, notes, and snippets.

@iSkore
Last active September 29, 2016 12:10
Show Gist options
  • Save iSkore/86c70bd803056ede6e45bc2c8bd2c2f1 to your computer and use it in GitHub Desktop.
Save iSkore/86c70bd803056ede6e45bc2c8bd2c2f1 to your computer and use it in GitHub Desktop.
Super fast random string generator
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