Skip to content

Instantly share code, notes, and snippets.

@CooLNuanfeng
Last active August 29, 2015 14:04
Show Gist options
  • Save CooLNuanfeng/455ca4912eeb3f5b9e9c to your computer and use it in GitHub Desktop.
Save CooLNuanfeng/455ca4912eeb3f5b9e9c to your computer and use it in GitHub Desktop.
生成随机字符串(0~9,a~z)
/**
* @function:generateRandomAlphaNum->生成随机的字符串
* @param:len->生存随机字符串的长度
* @tdd->IE6-9 chrome Firefox通过测试
*
*/
function generateRandomAlphaNum(len) {
var rdmString = "";
//toSting接受的参数表示进制,默认为10进制。36进制为0-9 a-z
for (var i=0; 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