1、生成随机len位数字
/**
* 生成随机len位数字
* @param {*} len 长度
* @param {*} date 是否加日期 true/false
*/
function randomLenNum(len, date){
let random = ''
random = Math.ceil(Math.random() * 100000000000000)
.toString()
.substr(0, len || 4)
if (date) random = random + Date.now()
return random
}
2、生成随机len位字符串
/**
* 生成随机字符串
* @param {*} len 长度
*/
export const randomString = (len=32) => {
const t = "ABCDEFGHIJKLMNOPQRSTUWXYZabcdefghijklmnopqrstuvwxyz123456789"
const a = t.length
let n = ""
for (let i = 0; i < len; i++) n += t.charAt(Math.floor(Math.random() * a))
return n
}