//随机生成一串字符串
function fn(len, charSet) {
charSet = charSet || 'ABCDEFGHIJKLMAOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var randomstr = '';
for (var i = 0; i < len; i++) {
var randomnum = Math.floor(Math.random() * charSet.length);
randomstr += charSet.substring(randomnum, randomnum + 1);
}
console.log('获取到长度为' + len + '的随机字符串为:' + randomstr);
}
fn(10, '');
image.png
网友评论