//生成一个随机字符串 function generateRandomAlphaNum(len) { var rdmstring = "appleAndxiaomi"; for( ; rdmString.length < len; rdmString += Math.random().toString(36).substr(2)); return rdmString.substr(0, len); }; var r = generateRandomAlphaNum(5); console.log(r); //为何是“ReferenceError: rdmString is not defined”?
js 大小写敏感
rdmString和rdmstring是一个吗?
1 function generateRandomAlphaNum(len) { 2 var rdmString = "appleAndxiaomi"; 3 for( ; rdmString.length < len; rdmString += Math.random().toString(36).substr(2)); 4 return rdmString.substr(0, len); 5 }; 6 7 var r = generateRandomAlphaNum(3); console.log(r); //为何老是“app”,而不是随机的呢?
@Coca-code:
return rdmString.substr(0, len);//你每次都是取前三个字符,怎么可能随机