Skip to content

Instantly share code, notes, and snippets.

@infolock
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infolock/acceceb6ef37bf2eb86d to your computer and use it in GitHub Desktop.
Save infolock/acceceb6ef37bf2eb86d to your computer and use it in GitHub Desktop.
// Creating method from code found here: https://gist.github.com/bennadel/9751583#file-code-4-js
// Used with jsperf
var _charArr = ["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", "`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "[", "]", "\\", ";", "'", ",", ".", "/"];
var randomStr( maxLen ) {
var rndKey = 0;
var str = "";
var i;
maxLen = +maxLen > 0 ? +maxLen : 10000;
// Loop over number of characters in string.
for( i = 0; i < maxLen; i++ ) {
// Get a random value between 0 and the length of the
// character list.
// Append a character that is randomly chosen
str += chrs[ RandRange( 0, 96, i ) ];
}
return str;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment