GUID 100%是唯一的吗?

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


当前回答

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

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

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

其他回答

而每个生成的GUID不是 保证是唯一的,总数 唯一键数(2128或 3.4×1038)是如此之大,相同的数字的概率是 生成两次是非常小的。为 例如,考虑可观察对象 宇宙,其中包含约5×1022 星星;每颗恒星都有可能 6.8×1015通用唯一的guid。

从维基百科。


这是一些关于如何创建GUID(用于。net)以及如何在正确的情况下获得相同的GUID的好文章。

https://ericlippert.com/2012/04/24/guid-guide-part-one/

https://ericlippert.com/2012/04/30/guid-guide-part-two/

https://ericlippert.com/2012/05/07/guid-guide-part-three/

​​

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。

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

从维基:

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

在这里输入图像描述

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

MSDN:

新Guid的值全为零或等于任何其他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.