/** * 生成一个随机字符串 * @param {number} length - 随机字符串长度 * @param {string} [dict] - 随机字符字典,默认为 a—Z0-9 * @returns {string} */ export function rollString(length: number, dict: string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") { let text = "" const possible = dict for (let i = 0; i < length; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)) return text }