示例代码如下
/**生成随机字符串, len是长度 */
function randomString(len) {
len = len || 32;
let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
let maxPos = $chars.length;
let pwd = '';
for (i = 0; i < len; i++)
pwd += $chars.charAt(Math.floor(Math.random() * maxPos))
return pwd;
}
console.log(randomString(2))