日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python int64,如何从Python生成唯一的64位整数?

發布時間:2024/10/14 python 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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位整数?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。