?随机生成一定长度的字符串
/**
* 获得一个随机的字符串(只包含数字和字符)
* @param {Integer} length 字符串的长度
* @return 随机字符串
*/
export function randomString(length) {
const BASE_NUMBER = '0123456789'
const BASE_CHAR = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-'
const baseString = BASE_CHAR + BASE_NUMBER
if (length < 1) {
length = 1
}
let character = ''
const baseLength = baseString.length
for (let i = 0; i < length; i++) {
const number = Math.floor(Math.random() * (baseLength))
character += baseString.charAt(number)
}
return character
}