醉菜鸟 2021-11-30 09:00:26

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

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