Guid Uniqueness On different machine [duplicate]

空扰寡人 提交于 2019-11-30 12:57:01
Tilak

GUID are "practically" universally unique.

A GUID is a 128-bit integer (16 bytes) that can be used across all computers and networks wherever a unique identifier is required. Such an identifier has a very low probability of being duplicated.

From the MSDN

It is generally accepted that a new random GUID will ALWAYS be unique. Probabilistically this is not true, but the likelihood of generating a dupe is so small we don't need to care about it.

The odds of generating two identical guids is 1 in 5,316,911,983,139,663,491,615,228,241,121,400,000

So if you generate 1 million guids on 1 million computers, the odds of generating a duplicate are: 1 in 5,316,911,983,139,663,491,615,228

Take 1 billion guids on 1 billion computers, odds of generating a dupe are: 1 in 5,316,911,983,139,663,491 (that's 5.3 quintillion).

The numbers speak for themselves, you're not going to generate a dupe.

In case you're wondering where I'm getting these numbers, the value part of a GUID is 122 bit. 2^122 is 5.3169119831396634916152282411214 x 10^36

Some more crazy figures...
If you generate 1 million guids per second, it would take 168,486,464,147,580,370,470,736 years to probabilistically guarantee a duplicate.

@viggity mentioned some guids have 48 bits taken by a mac address, the numbers are still staggering hence the affordability to lose those bits. Taking the above example of 2 million guids per second (on the same computer), it would still take 598,584,166 years to guarantee a dupe. That's 600 million years. That's longer than life has existed on Earth. Or if you're a Young Earth Creationist, that's at least 60 thousand times the lifespan of Earth.

I remember hearing somewhere that if you visualized the IPV4 address space (32 bits) as being the size of postage stamp, IPV6 (128 bits) is the size of our solar system. Generating a dupe is just not going to happen.

Also, if anything you're more likely to get a duplicate the same machine than two different machines because most Guid generation algorithms will embed your computers NIC MAC address within the guid (it's 48 bits). Although there are algorithms that don't embed the MAC address and are just purely random. see: http://guid.us/

Edit: another fun scale example the volume of the earth is roughly 10^27 cubic centimeters. meaning that every cubic centimeter for the ENTIRE VOLUME of the earth could have 340,000,000,000 guids all to itself. this number is mindbogglingly big.

Alternatively, every square NANOmeter of the surface of the earth could have roughly 650,000 guids all to itself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!