欢迎访问 生活随笔!

尊龙游戏旗舰厅官网

当前位置: 尊龙游戏旗舰厅官网 > 编程语言 > python >内容正文

python

python int64,如何从python生成唯一的64位整数? -尊龙游戏旗舰厅官网

发布时间:2024/10/14 python 17 豆豆
尊龙游戏旗舰厅官网 收集整理的这篇文章主要介绍了 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位整数?的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得尊龙游戏旗舰厅官网网站内容还不错,欢迎将尊龙游戏旗舰厅官网推荐给好友。

网站地图