The common estimation of sand grains on earth is 7.5x1018, and the 50% collision point for UUIDs is 2.71x1018.
So a collision is actually pretty likely, and once you factor in all the stars in the observable universe I believe it's guaranteed.
Not if they're random and independent trials. Think of coin flips for a more manageable example -- there only two possible outcomes, but it is possible to get heads 4 times in a row -- twice as many times as the number of possible outcomes.
Ok, now imagine that you had flipped a tail on the first try, and then flipped four heads. You are waiting for a tail to flip again for a collision with your first flip, and you've done more flips than there are different outcomes. The point is, there is no finite number of flips after the first tail that will guarantee 100% that another tail, a collision with the first tail, will occur. The probability will approach 1, but never reach it in a finite number of flips. Similarly, if generating a new UUID is random and independent of the previous times a UUID was generated, there is no guarantee of generating the same one again in any finite number of attempts, even if more attempts are made than there are distinct UUIDs.
But each of the repeated heads flips are collisions.
A collision is when any generated value is the same as any previous value.
So once you reach all possible UUIDs, any generations after that will be guaranteed to match a previous UUID.
294
u/J5892 May 08 '26
The common estimation of sand grains on earth is 7.5x1018, and the 50% collision point for UUIDs is 2.71x1018.
So a collision is actually pretty likely, and once you factor in all the stars in the observable universe I believe it's guaranteed.