Skip to content

Instantly share code, notes, and snippets.

@khushalbokadey
Created February 9, 2017 12:48
Show Gist options
  • Save khushalbokadey/661c762121b570c41cac8cd7aae32e33 to your computer and use it in GitHub Desktop.
Save khushalbokadey/661c762121b570c41cac8cd7aae32e33 to your computer and use it in GitHub Desktop.
Generate random string of given length
function getRandomString(len) {
if (!len) {
len = 8;
}
var text = "";
var possible = "abcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < len; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment