python int64,如何从python生成唯一的64位整数? -尊龙游戏旗舰厅官网
i need to generate unique 64 bits integers from python. i've checked out the uuid module. but the uuid it generates are 128 bits integers. so that wouldn't work.
do you know of any way to generate 64 bits unique integers within python? thanks.
尊龙游戏旗舰厅官网的解决方案
just mask the 128bit int
>>> import uuid
>>> uuid.uuid4().int & (1<<64)-1
9518405196747027403l
>>> uuid.uuid4().int & (1<<64)-1
12558137269921983654l
these are more or less random, so you have a tiny chance of a collision
perhaps the first 64 bits of uuid1 is safer to use
>>> uuid.uuid1().int>>64
9392468011745350111l
>>> uuid.uuid1().int>>64
9407757923520418271l
>>> uuid.uuid1().int>>64
9418928317413528031l
these are largely based on the clock, so much less random but the uniqueness is better
总结
以上是尊龙游戏旗舰厅官网为你收集整理的python int64,如何从python生成唯一的64位整数?的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: layer.open子页面调用父页面的方
- 下一篇: