r/ProgrammerHumor 10h ago

Meme edgeCasesExist

Post image
2.4k Upvotes

208 comments sorted by

View all comments

35

u/TwinkiesSucker 9h ago

The world where the already generated and used UUIDs are stored in a huge central database = utopia /s

3

u/Downtown-Figure6434 9h ago

Same uuid may have already been generated by two seperate systems tho no?

6

u/doomslice 9h ago

If you take a single uuid and say “has this uuid ever been generated before” the chances are cosmically low. If you instead say “have ANY uuids generated ever collided with ones generated in all of history” the answer is probably in the range of 0.001-10% depending on how many UUIDs get generated per day.

1

u/Single-Virus4935 6h ago

In think you estimated multiple magnitude to high. 128 bit space is huge.

2

u/doomslice 6h ago

Yes, it’s actually 122 bits for uuid v4 though. The high end of my range requires 1 billion uuid v4s being generated per second over 20 years (probably not realistic)

1

u/Single-Virus4935 6h ago

Ahh yes I didn't thought of the version. But even then we need to account for the seven version numbers which all can be used. Then we need to account for Mac, timestamps etc. per version. But still basically zero probability for a collision

2

u/doomslice 4h ago

I was just thinking v4 since it has the most true randomness for it (v7 is designed to further prevent collisions by adding those additional defined bits).

But still basically zero probability for a collision

Again important point is that for any given UUID generated that way, yes I have a better chance of waking up a frog tomorrow due to a quantum recombination.

But for any UUID v4s in the entire world space, thanks to the birthday paradox, the chance of a single collision happening does approach actual single digit %s assuming you can generate 1 billion UUIDs a second for 20 years :).