Skip to content

Instantly share code, notes, and snippets.

@alexcorvi
Created April 25, 2015 12:05
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 alexcorvi/fa16b325c9b71c20e6dd to your computer and use it in GitHub Desktop.
Save alexcorvi/fa16b325c9b71c20e6dd to your computer and use it in GitHub Desktop.
Javascript: Function to create random string
var getChars = function (size) {
var str = '',
i = 0,
chars = '0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ';
while (i < size) {
str += chars.substr(Math.floor(Math.random() * 62), 1);
i++;
}
return str;
}
console.log(getChars(8));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment