GUID 100%是唯一的吗?
它会在多个线程中保持唯一吗?
GUID 100%是唯一的吗?
它会在多个线程中保持唯一吗?
当前回答
Eric Lippert写了一系列关于guid的非常有趣的文章。
There are on the order 230 personal computers in the world (and of course lots of hand-held devices or non-PC computing devices that have more or less the same levels of computing power, but lets ignore those). Let's assume that we put all those PCs in the world to the task of generating GUIDs; if each one can generate, say, 220 GUIDs per second then after only about 272 seconds -- one hundred and fifty trillion years -- you'll have a very high chance of generating a collision with your specific GUID. And the odds of collision get pretty good after only thirty trillion years.
GUID指南,第一部分 GUID指南,第二部分 GUID指南,第三部分
其他回答
如果你的系统时钟设置正确,没有被环绕,如果你的网卡有自己的MAC(即你没有设置自定义MAC),你的网卡供应商没有回收MAC(他们不应该这样做,但已经知道发生了),如果你的系统的GUID生成功能正确实现,那么你的系统将永远不会生成重复的GUID。
如果地球上每个生成guid的人都遵循这些规则,那么您的guid将是全局唯一的。
在实践中,违反规则的人数很少,他们的guid不太可能“逃脱”。冲突在统计上是不可能发生的。
MSDN:
新Guid的值全为零或等于任何其他Guid的概率非常低。
而每个生成的GUID不是 保证是唯一的,总数 唯一键数(2128或 3.4×1038)是如此之大,相同的数字的概率是 生成两次是非常小的。为 例如,考虑可观察对象 宇宙,其中包含约5×1022 星星;每颗恒星都有可能 6.8×1015通用唯一的guid。
从维基百科。
这是一些关于如何创建GUID(用于。net)以及如何在正确的情况下获得相同的GUID的好文章。
https://ericlippert.com/2012/04/24/guid-guide-part-one/
https://ericlippert.com/2012/04/30/guid-guide-part-two/
https://ericlippert.com/2012/05/07/guid-guide-part-three/
我经历了一个重复的GUID。
我使用的是Neat收据桌面扫描仪,它自带专有数据库软件。该软件有一个同步到云的功能,我总是在同步时得到一个错误。浏览一下日志,你会发现这句话非常棒:
"errors":[{"code":1,"message":"creator_guid: is already . 了”、“guid”:“c83e5734 d77a - 4 - b09 b8c1 - 9623 cac7b167”}]}
我有点难以置信,但可以肯定的是,当我找到进入本地网络数据库的方法并删除包含该GUID的记录时,错误就停止了。
所以用轶事证据来回答你的问题,没有。副本是可能的。但它发生的原因很可能不是由于偶然,而是由于标准的做法在某种程度上没有得到遵守。(我只是没有那么幸运)然而,我不能肯定。这不是我的软件。
他们的客户支持非常有礼貌和乐于助人,但他们以前肯定从未遇到过这个问题,因为在与他们电话交谈3个多小时后,他们没有找到解决方案。(总之,Neat给我留下了深刻的印象,这个小故障虽然令人沮丧,但并没有改变我对他们产品的看法。)
Eric Lippert写了一系列关于guid的非常有趣的文章。
There are on the order 230 personal computers in the world (and of course lots of hand-held devices or non-PC computing devices that have more or less the same levels of computing power, but lets ignore those). Let's assume that we put all those PCs in the world to the task of generating GUIDs; if each one can generate, say, 220 GUIDs per second then after only about 272 seconds -- one hundred and fifty trillion years -- you'll have a very high chance of generating a collision with your specific GUID. And the odds of collision get pretty good after only thirty trillion years.
GUID指南,第一部分 GUID指南,第二部分 GUID指南,第三部分