Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a GUID unique 100% of the time?

Is a GUID unique 100% of the time?

Will it stay unique over multiple threads?

like image 205
David Basarab Avatar asked Sep 02 '08 15:09

David Basarab


People also ask

How much of a GUID is unique?

The GUID generation algorithm relies on the fact that it has all 16 bytes to use to establish uniqueness, and if you throw away half of it, you lose the uniqueness. There are multiple GUID generation algorithms, but I'll pick one of them for concreteness, specifically the version described in this Internet draft.

Is GUID truly unique?

A GUID is a unique number that can be used as an identifier for anything in the universe, but unlike ISBN there is no central authority - the uniqueness of a GUID relies on the algorthm that was used to generate it.

Is GUID truly random?

Definitely not random. Similarly, the person who wanted to use a GUID for password generation would find that the passwords are totally predictable if you know what time the GUID was generated and which computer generated the GUID (which you can get by looking at the final six bytes from some other password-GUID).

Does GUID contain timestamp?

The javadoc for UUID says the following about the timestamp field: The 60 bit timestamp value is constructed from the time_low, time_mid, and time_hi fields of this UUID. The resulting timestamp is measured in 100-nanosecond units since midnight, October 15, 1582 UTC.


2 Answers

While each generated GUID is not guaranteed to be unique, the total number of unique keys (2128 or 3.4×1038) is so large that the probability of the same number being generated twice is very small. For example, consider the observable universe, which contains about 5×1022 stars; every star could then have 6.8×1015 universally unique GUIDs.

From Wikipedia.


These are some good articles on how a GUID is made (for .NET) and how you could get the same guid in the right situation.

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/

​​

like image 190
Adam Davis Avatar answered Sep 21 '22 11:09

Adam Davis


If you are scared of the same GUID values then put two of them next to each other.

Guid.NewGuid().ToString() + Guid.NewGuid().ToString(); 

If you are too paranoid then put three.

like image 25
Bura Chuhadar Avatar answered Sep 22 '22 11:09

Bura Chuhadar