GUID 100%是唯一的吗?
它会在多个线程中保持唯一吗?
GUID 100%是唯一的吗?
它会在多个线程中保持唯一吗?
当前回答
“GUID是100%唯一的吗?”的答案是“不是”。
如果你想要GUID的100%唯一性,然后做下面的事情。 生成GUID 检查GUID是否存在于您正在寻找唯一性的表列中 如果存在,则转步骤1,否则转步骤4 使用这个GUID作为唯一的。
其他回答
如果你的系统时钟设置正确,没有被环绕,如果你的网卡有自己的MAC(即你没有设置自定义MAC),你的网卡供应商没有回收MAC(他们不应该这样做,但已经知道发生了),如果你的系统的GUID生成功能正确实现,那么你的系统将永远不会生成重复的GUID。
如果地球上每个生成guid的人都遵循这些规则,那么您的guid将是全局唯一的。
在实践中,违反规则的人数很少,他们的guid不太可能“逃脱”。冲突在统计上是不可能发生的。
简单的答案是肯定的。
Raymond Chen写了一篇关于guid和为什么guid的子字符串不能保证唯一的文章。这篇文章深入探讨了guid的生成方式以及它们用来确保唯一性的数据,这应该会花一些篇幅来解释它们为什么会这样:-)
I think that when people bury their thoughts and fears in statistics, they tend to forget the obvious. If a system is truly random, then the result you are least likely to expect (all ones, say) is equally as likely as any other unexpected value (all zeros, say). Neither fact prevents these occurring in succession, nor within the first pair of samples (even though that would be statistically "truly shocking"). And that's the problem with measuring chance: it ignores criticality (and rotten luck) entirely.
如果真的发生了,结果是什么?你的软件停止工作了吗?有人受伤了吗?有人死了吗?世界会爆炸吗?
临界性越极端,“概率”这个词就越难听。最后,链接guid(或XORing它们,或其他什么)是当你(主观地)认为你的特定临界性(和你的“幸运”感觉)是不可接受的时候所做的事情。如果它能毁灭世界,那么请代表我们所有没有参与大型强子对撞机核试验的人,不要使用guid或任何其他不确定的东西!
是的,GUID应该总是唯一的。它是基于硬件和时间,加上一些额外的位,以确保它是唯一的。我相信理论上有可能得到两个一模一样的,但在现实场景中极不可能。
以下是Raymond Chen关于Guids的一篇很棒的文章:
https://blogs.msdn.com/oldnewthing/archive/2008/06/27/8659071.aspx
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指南,第三部分