假定GUID始终是唯一的是否安全? [英] Is it safe to assume a GUID will always be unique?

查看:101
本文介绍了假定GUID始终是唯一的是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道发生冲突的可能性很小,但是如果我生成了一批1000个GUID(例如),是否可以安全地假设它们都是唯一的以保存每个GUID?

I know there is a minute possibility of a clash but if I generated a batch of 1000 GUIDs (for example), would it be safe to assume they're all unique to save testing each one?

奖励问题

测试GUID唯一性的最佳方法?布隆过滤器也许?

An optimal way to test a GUID for uniqueness? Bloom filter maybe?

推荐答案

是的,可以.由于GUID的长度为128位,因此冲突的可能性很小,但分钟"一词的强度还远远不够. 如此之多的GUID ,如果您随机生成其中的几万亿,那么您甚至更有可能被陨石击中而不是发生一次碰撞(来自维基百科).而且,如果您不是随机生成它们,而是使用MAC地址和时间戳算法 eg ,那么它们也将是唯一的,因为MAC地址在计算机之间是唯一的和时间戳在您的计算机上是唯一的.

Yes, you can. Since GUIDs are 128 bits long, there is admittedly a minute possibility of a clash—but the word "minute" is nowhere near strong enough. There are so many GUIDs that if you generate several trillion of them randomly, you're still more likely to get hit by a meteorite than to have even one collision (from Wikipedia). And if you aren't generating them randomly, but are e.g. using the MAC-address-and-time-stamp algorithm, then they're also going to be unique, as MAC addresses are unique among computers and time stamps are unique on your computer.

为了回答您的奖励问题,测试一组GUID唯一性的最佳方法是仅假设它们都是唯一的.为什么?因为,鉴于给定的GUID数量,GUID碰撞的几率小于宇宙射线在您的计算机内存中翻转一点并弄乱您所关心的任何准确"算法给出的答案的几率跑步. (请参阅此StackOverflow答案进行数学运算.)

Edit 1: To answer your bonus question, the optimal way to test a set of GUIDs for uniqueness is to just assume that they are all are unique. Why? Because, given the number of GUIDs you're generating, the odds of a GUID collision are smaller than the odds of a cosmic ray flipping a bit in your computer's memory and screwing up the answer given by any "accurate" algorithm you'd care to run. (See this StackOverflow answer for the math.)

那里有数量众多的GUID.引用道格拉斯·亚当斯(Douglas Adams)的银河系漫游指南:

There are an enormous number of GUIDs out there. To quote Douglas Adams's Hitchhiker's Guide to the Galaxy:

空间"很大,确实很大.您只是不敢相信它是如此之大,令人难以置信.我的意思是您可能认为这对化学家来说还有很长的路要走,但这仅仅是花生到太空,听着……"

"Space," it says, "is big. Really big. You just won't believe how vastly hugely mindbogglingly big it is. I mean you may think it's a long way down the road to the chemist, but that's just peanuts to space, listen…"

而且由于宇宙中有大约7×10 22 颗恒星,并且在2个 128 GUID之下,则每个单个的GUID大约为4.86×10 15 星星.如果这些星星中的每一个都有一个像我们这样繁华人口的世界,那么在每个星星周围, 每一个曾经居住过的人类或外星人 都将有权获得超过四万五千GUID.对于历史上每个人在宇宙中每一个恒星. GUID空间的巨大程度与整个宇宙的大小相同.您不必担心.

And since there are about 7×1022 stars in the universe, and just under 2128 GUIDs, then there are approximately 4.86×1015—almost five quadrillion—GUIDs for every single star. If every one of those stars had a world with a thriving population like ours, then around each and every star, every human or alien who had ever lived would be entitled to over forty-five thousand GUIDs. For every person in history at every star in the universe. The GUID space is at the same level of hugeness as the size of the entire universe. You do not need to worry.

(对此进行思考:哇.我还没意识到我自己这是什么意思.GUID空间非常庞大.我有点敬畏.)

(Edit 2: Reflecting on this: wow. I hadn't realized myself what this meant. The GUID space is incomprehensibly massive. I'm sort of in awe of it.)

这篇关于假定GUID始终是唯一的是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆