Skip to content

Instantly share code, notes, and snippets.

@hehongwei44
Last active August 29, 2015 14:03
Show Gist options
  • Save hehongwei44/62d64830afa07ddac65f to your computer and use it in GitHub Desktop.
Save hehongwei44/62d64830afa07ddac65f to your computer and use it in GitHub Desktop.
生成随机字符串(数字+字母),长度自定义
/**
* @function:generateRandomAlphaNum->生成随机的字符串
* @param:len->生存随机字符串的长度
* @tdd->IE6-9 chrome Firefox通过测试
*
*/
function generateRandomAlphaNum(len) {
var rdmString = "";
//toSting接受的参数表示进制,默认为10进制。36进制为0-9 a-z
for (; rdmString.length < len; rdmString += Math.random().toString(36).substr(2));
return rdmString.substr(0, len);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment