Skip to content

📚 6.生成唯一id

💻 代码实现

typescript
function GetUniqueID() {
    // 当前时间转成 36 进制字符串
    var time = Date.now().toString(36)
    console.log("🚀 ~ GetUniqueID ~ time:", time)
    // 当前随机数转成 36 进制字符串
    var random = Math.random().toString(36)
    // 去除随机数的 0. 字符串
    random = random.substring(2, random.length)
    // 返回唯一ID
    return random + time
}
// 测试输出
console.log(GetUniqueID())

Released under the MIT License.