64位随机ID是否足以容纳大约1000万个条目?(Is a 64 bit random ID good enough for about 10 million entries?)

编程入门 行业动态 更新时间:2024-10-28 01:26:42
64位随机ID是否足以容纳大约1000万个条目?(Is a 64 bit random ID good enough for about 10 million entries?)

我受到这个唯一id代码的启发,生成一个随机的64位标识符。

我的问题:这对于大约1000万条记录是否足够好?

def self.generateId (0..15).collect{(rand*16).to_i.to_s(16)}.join end

I was inspired by this unique id code to generate a random 64 bit identifier.

My question: will this be good enough for about 10 million entries?

def self.generateId (0..15).collect{(rand*16).to_i.to_s(16)}.join end

最满意答案

这是经典的生日问题。

m=10^7且n=10^20 (自2^64 ~ 10^20 ),碰撞概率由下式给出:

p = 1 - exp(-m^2/(2*n))

给出5e-07的碰撞概率

我会说没有替换的采样是你最好的选择。

This is classic birthday problem.

With m=10^7 and n=10^20 (Since 2^64 ~ 10^20), and the collision probability is given by:

p = 1 - exp(-m^2/(2*n))

Gives a collision probability of 5e-07

I would say sampling without replacement is your best option.

更多推荐

本文发布于:2023-08-02 10:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1375399.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:条目   万个   ID   bit   million

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!