编辑代码


// const startDate = new Date('2025-05-29T00:00:00')
// const startDate = new Date('2025-05-30')
// const startDate = new Date()
// const startMs = startDate.getTime()
const startMs = 1748583811638

function random(max){
    if(max<=0) max = 4
    return Math.ceil(Math.random() * 100000) % max
}

function snowflowerId(){
    let bits = '0'+(Date.now() - startMs).toString(2)
    bits = bits+random(2).toString(2)
    bits = bits+random(128).toString(2)
    
    return parseInt(bits,2).toString()
}

const id = snowflowerId()

console.log("ID",id,id.length)