GUID 100%是唯一的吗?
它会在多个线程中保持唯一吗?
GUID 100%是唯一的吗?
它会在多个线程中保持唯一吗?
当前回答
如果你害怕相同的GUID值,那么把它们放在一起。
Guid.NewGuid().ToString() + Guid.NewGuid().ToString();
如果你太多疑,那就放三个。
其他回答
从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.
这种情况不应该发生。然而,当. net负载过重时,可能会得到重复的guid。我有两个不同的web服务器使用两个不同的sql服务器。我去合并数据,发现我有1500万个guids和7个副本。
MSDN:
新Guid的值全为零或等于任何其他Guid的概率非常低。
在多线程/多进程单元测试期间,我经历过guid不是唯一的(也是?)我想这与所有其他条件相同的情况下,伪随机生成器的相同播种(或缺乏播种)有关。我用它来生成唯一的文件名。我发现操作系统在这方面做得更好:)
恶意破坏预警
你问guid是否100%唯一。这取决于它在guid中必须是唯一的。当guid的数量接近无穷大时,重复guid的概率接近100%。
GUID代表全局唯一标识符
简而言之: (线索就在名字里)
详细: guid被设计为唯一的;它们是使用基于计算机时钟和计算机本身的随机方法计算的,如果你在同一毫秒内在同一台机器上创建多个guid,它们可能是匹配的,但对于几乎所有的正常操作,它们应该被认为是唯一的。