Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
yitter 7bba4e1cd3 | 2 years ago | |
---|---|---|
.. | ||
source | 2 years ago | |
README.md | 2 years ago | |
test.py | 2 years ago |
Python 3.6+
# 导入包
from source import Options,Generator
# 声明id生成器参数,需要自己构建一个workerId
options = Options.IdGeneratorOptions(workerId=23)
# 参数中,WorkerIdBitLength 默认值6,支持的 WorkerId 最大值为2^6-1,若 WorkerId 超过64,可设置更大的 WorkerIdBitLength
idgen = Generator.DefaultIdGenerator()
# 保存参数
idgen.SetIdGernerator(options)
# 生成id
uid = idgen.NextId()
# 打印出来查看
print("%d, %x" % (uid,uid))
雪花算法中非常好用的数字ID生成器
C C# Pascal Go D other