GUID 100%是唯一的吗?

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


当前回答

是的,GUID应该总是唯一的。它是基于硬件和时间,加上一些额外的位,以确保它是唯一的。我相信理论上有可能得到两个一模一样的,但在现实场景中极不可能。

以下是Raymond Chen关于Guids的一篇很棒的文章:

https://blogs.msdn.com/oldnewthing/archive/2008/06/27/8659071.aspx ​ ​ ​

其他回答

在多线程/多进程单元测试期间,我经历过guid不是唯一的(也是?)我想这与所有其他条件相同的情况下,伪随机生成器的相同播种(或缺乏播种)有关。我用它来生成唯一的文件名。我发现操作系统在这方面做得更好:)

恶意破坏预警

你问guid是否100%唯一。这取决于它在guid中必须是唯一的。当guid的数量接近无穷大时,重复guid的概率接近100%。

GUID 100%是唯一的吗?

不能保证,因为有几种方法可以生成一个。然而,您可以尝试计算创建两个完全相同的GUID的几率,您就会明白:一个GUID有128位,因此,有2128个不同的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指南,第三部分

我经历了一个重复的GUID。

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

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

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

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

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

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