GUID 100%是唯一的吗?

它会在多个线程中保持唯一吗?


当前回答

从http://www.guidgenerator.com/online-guid-generator.aspx

What is a GUID? GUID (or UUID) is an acronym for 'Globally Unique Identifier' (or 'Universally Unique Identifier'). It is a 128-bit integer number used to identify resources. The term GUID is generally used by developers working with Microsoft technologies, while UUID is used everywhere else. How unique is a GUID? 128-bits is big enough and the generation algorithm is unique enough that if 1,000,000,000 GUIDs per second were generated for 1 year the probability of a duplicate would be only 50%. Or if every human on Earth generated 600,000,000 GUIDs there would only be a 50% probability of a duplicate.

其他回答

足够的guid来为可见宇宙中每一颗恒星周围的每一颗假设行星上的每一颗假设沙粒分配一个guid。

以至于如果世界上的每台计算机每秒生成1000个guid,持续200年,就可能发生碰撞。

考虑到当前guid的本地使用数量(例如,每个数据库每个表一个序列),这对于我们这些有限的生物来说是非常不可能成为问题的(对于手机来说,寿命通常不到十年,如果不是一两年的话)。

... 我们现在可以结束这个话题了吗?

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指南,第三部分

MSDN:

新Guid的值全为零或等于任何其他Guid的概率非常低。

理论上讲,不,它们不是唯一的。可以反复生成相同的guid。然而,这种情况发生的几率非常低,你可以假设它们是独一无二的。

我以前读到过,这种可能性非常低,你真的应该关注其他事情——比如你的服务器自燃或代码中的其他错误。也就是说,假设它是唯一的,不要构建任何“捕获”重复的代码——把时间花在更有可能发生的事情上(即任何其他事情)。

我尝试向我的博客读者(非技术家庭成员)描述guid的有用性。从那里(通过维基百科),生成重复GUID的几率:

1 / 2^128 1 / 340的十一分之一(别担心,十一分之一不在 测试) 1 / 3.4 × 10^38 1 / 340,000,000,000,000,000,000,000,000,000,000,000,000,000,000

这种情况不应该发生。然而,当. net负载过重时,可能会得到重复的guid。我有两个不同的web服务器使用两个不同的sql服务器。我去合并数据,发现我有1500万个guids和7个副本。