GUID 100%是唯一的吗?

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


当前回答

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或任何其他不确定的东西!

其他回答

从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.

MSDN:

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

最难的部分不是生成重复的Guid。

最难的部分是设计一个数据库来存储所有生成的数据,以检查它是否实际上是重复的。

从维基:

例如,为了有至少一次碰撞的50%概率,需要生成的随机版本4 uuid的数量为2.71 quintillion,计算如下:

在这里输入图像描述

这个数字相当于在大约85年的时间里每秒生成10亿个UUID,而包含这么多UUID的文件(每个UUID 16个字节)大约是45艾字节,比目前存在的最大数据库(几百pb量级)大很多倍

顺便说一句,我在Windows XP中使用了Volume guid。这是一个非常模糊的分区布局,有3个磁盘和14个卷。

\\?\Volume{23005604-eb1b-11de-85ba-806d6172696f}\ (F:)
\\?\Volume{23005605-eb1b-11de-85ba-806d6172696f}\ (G:)
\\?\Volume{23005606-eb1b-11de-85ba-806d6172696f}\ (H:)
\\?\Volume{23005607-eb1b-11de-85ba-806d6172696f}\ (J:)
\\?\Volume{23005608-eb1b-11de-85ba-806d6172696f}\ (D:)
\\?\Volume{23005609-eb1b-11de-85ba-806d6172696f}\ (P:)
\\?\Volume{2300560b-eb1b-11de-85ba-806d6172696f}\ (K:)
\\?\Volume{2300560c-eb1b-11de-85ba-806d6172696f}\ (L:)
\\?\Volume{2300560d-eb1b-11de-85ba-806d6172696f}\ (M:)
\\?\Volume{2300560e-eb1b-11de-85ba-806d6172696f}\ (N:)
\\?\Volume{2300560f-eb1b-11de-85ba-806d6172696f}\ (O:)
\\?\Volume{23005610-eb1b-11de-85ba-806d6172696f}\ (E:)
\\?\Volume{23005611-eb1b-11de-85ba-806d6172696f}\ (R:)
                                     | | | | |
                                     | | | | +-- 6f = o
                                     | | | +---- 69 = i
                                     | | +------ 72 = r
                                     | +-------- 61 = a
                                     +---------- 6d = m

这并不是说guid非常相似,而是所有的guid都有字符串“mario”。这是巧合还是另有原因?

现在,当在GUID中搜索第4部分时,我发现大约有125,000个与音量GUID相关的点击。

结论:当涉及到Volume guid时,它们并不像其他guid那样独特。

如果你害怕相同的GUID值,那么把它们放在一起。

Guid.NewGuid().ToString() + Guid.NewGuid().ToString();

如果你太多疑,那就放三个。