js中生成随机且唯一的字符串

醉菜鸟 2022-05-19 08:00:14

/**
 * 生成唯一字符串
 * @returns {string}
 */
function createUniqueString() {
    const timestamp = +new Date() + '';
    const randomNum = parseInt((1 + Math.random()) * 65536) + '';
    return (+(randomNum + timestamp)).toString(32)
}
意见反馈