js 随机字符串

8537 人参与 | 时间:2024年03月29日 08:17:45
内容
export function randomStr(len, type = 1) {
var d,
e,
b = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
c = '',
f = 'abcdefghijklmnopqrstuvwxyz0123456789',
i = ''
if (type == 1) {
i = f
} else {
i = b
}
for (d = 0; len > d; d += 1) {
;(e = Math.random() * i.length), (e = Math.floor(e)), (c += i.charAt(e))
}
return c.toLowerCase()
}