使用十六进制生成一些随机字母和数字的最简单方法是什么?
例如:095904e8-121098-fb330c52-9ae4-4a44-a31d-b80f2c680ca0
答案 0 :(得分:2)
没有正则表达式的js
function randomString(len) {
len = len || 32;
var $chars = 'abcdefhiklmnorstuvwxz0123456789';
var maxPos = $chars.length;
var pwd = '';
for (i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
document.write(randomString(8)+'-'+randomString(6)+'-'+randomString(8)+'-'+randomString(4)+'-'+randomString(4)+'-'+randomString(4)+'-'+randomString(12));