Given that each GUID is represented by 16 bytes. So at best there are 2^128 possibilities = 3.4028237e+38 possible GUIDs.
Will it be possible that it will all be used up?
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.
Question: How many GUID combinations are there? Answer: There are 122 random bits (128 – 2 for variant – 4 for version) so this calculates to 2^122 or 5,316,911,983,139,663,491,615,228,241,121,400,000 possible combinations.
GUID generation algorithm 4 fills the GUID with 122 random bits. The odds of two GUIDs colliding are therefore one in 2¹²², which is a phenomenally small number. When you are dealing with rates this low, you have to adjust your frame of reference.
In general, yes it is safe to assume. If your GUID generator is truly random, the possibilities of a clash within a 1000 GUIDs is extraordinarily small.
To show you how big 2^128 GUIDs is:
1 GUID = 16 bytes
.
Therefore 2^128
GUIDS would need 2^4 * 2^128 bytes
to be stored.
2^4 * 2^128 = 2^132 bytes
Using Python, I calculated that this would take:4,951,760,157,141,521,099,596,496,896
terabytes.
So first you would need to worry about being able to store that many GUIDs, before you could even consider running out of them.
Basically: it is impossible for you to run out.
Just because I've heard people worry about collision so many times, I will expand my answer to include an analysis of the possibilities of collisions.
The average
number of UUIDs you would need until you get a collision is:
2^128 / 2 = 2^127
This means that there is a 50%
chance that by the time you generate 2^127
GUIDs, you will get a collision. The number of GUIDs you need for this is:
170141183460469231731687303715884105728 GUIDs
Someone please correct me if I'm wrong but: this means the potential for generating a collision is so small, it is not even worth checking if the UUID that was just generated already exists in your database.
Note: This is all assuming the UUIDs are generated with a good algorithm for Randomness and a good source of Entropy.
No. Even if you assume extremely high usage of GUIDs in some area, and extremely long time scales, the key point about GUIDs is their uniqueness. As soon as you start to get repetitions with any probability that is of practical relevance, people will stop using GUIDs, and therefore won't use up any more of them. Sure, they might use some numbers which look like GUIDs in some areas, where sufficiently low usage can still help ensure local uniqueness, but those would only be LUIDs, and with a bit of luck people will also call them this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With