GUID 100%是唯一的吗?

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


当前回答

MSDN:

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

其他回答

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

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

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。

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

从维基:

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

在这里输入图像描述

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

我经历了一个重复的GUID。

我使用的是Neat收据桌面扫描仪,它自带专有数据库软件。该软件有一个同步到云的功能,我总是在同步时得到一个错误。浏览一下日志,你会发现这句话非常棒:

"errors":[{"code":1,"message":"creator_guid: is already . 了”、“guid”:“c83e5734 d77a - 4 - b09 b8c1 - 9623 cac7b167”}]}

我有点难以置信,但可以肯定的是,当我找到进入本地网络数据库的方法并删除包含该GUID的记录时,错误就停止了。

所以用轶事证据来回答你的问题,没有。副本是可能的。但它发生的原因很可能不是由于偶然,而是由于标准的做法在某种程度上没有得到遵守。(我只是没有那么幸运)然而,我不能肯定。这不是我的软件。

他们的客户支持非常有礼貌和乐于助人,但他们以前肯定从未遇到过这个问题,因为在与他们电话交谈3个多小时后,他们没有找到解决方案。(总之,Neat给我留下了深刻的印象,这个小故障虽然令人沮丧,但并没有改变我对他们产品的看法。)