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 endI 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.
更多推荐
发布评论