Skip to content

Instantly share code, notes, and snippets.

@ETiV
Created June 5, 2013 09:44
Show Gist options
  • Save ETiV/5712807 to your computer and use it in GitHub Desktop.
Save ETiV/5712807 to your computer and use it in GitHub Desktop.
JavaScript Generate Random String
// get random string by length `len`
function _getRandomString(len) {
len = len || 32;
var $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYAabcdefghijklmnopqrstuvwxyz0123456789_'; // string set
var maxPos = $chars.length;
var pwd = '';
for (i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment