js生成随机字符串

function randomString(len) {
   len = len || 32;
   var str = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
   var maxPos = str.length;
   var pwd = '';
   for (i = 0; i < len; i++) {
     pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
   }
   return pwd;
}
//输出16位随机字符串
console.log(randomString(16));

 

你可能感兴趣的:(js)