For example if you have a single UUID with a collision probability of x, if you concatenate 2 UUIDs, does the collision probability become x^2?

val0 = generate_uuid()
val1 = generate_uuid()

final_val = val0 + val1

So with each additional uuid, does it reduce the probability of collision exponentially? My x, and x^2 might also be flawed. I don't know how to formulate it.

EDIT: Consider uuid4 from python and joining them as strings. final_val is string.

有帮助吗?

解决方案

With version 4 (variant 1) random UUIDs there are 2^122 possible values. If we assume proper random* number generation that means that the chance of any two ids matching is around 1 in 5.32x10^36.

If you use 2 version 4 UUIDs together (let's call it a super UUID), you have 2^244 possible different values. That means the chance of 2 properly random* 'super UUIDs' the chance they collide is 1 in 2.83×10^73

So yes, having more numbers available makes it less likely but it was already incredibly unlikely in the first place. It's kind of like asking whether if you dip a cup in the ocean twice, a year separated, whether it's less likely to get the exact same set of water molecules on each attempt than you would if you did the same thing in Lake Superior.

*Unless you have special equipment to generate random numbers, then in practical terms we are really talking about psuedo-random numbers. As long as the PRNG is cryptographically secure (evenly distributed and chaotic, etc.) we can ingore that and treat them like true random numbers for this purpose.

其他提示

Version 5 UUIDs are guaranteed to be the same for the same input, which means that it is guaranteed that val0 and val1 are always the same.

Therefore, concatenating two, three, twenty, thirty, or a trillion UUIDs does not change the probability of a collision at all.

You can’t reduce the expected number of collision without using more bits. What you can do: You can use consecutive UUIDs, which means it is less likely to have any collision with other UUIDs if they use the same method, but if you have any collisions, you will get lots of them.

Yes, but also No.

say the collision chance is 50% obviously if you have two ids then its 0.5 * 0.5 = 0.25 if you have 3 its 0.5^3 etc

But if its 0 chance of collision, which it totally is, then its still 0 chance afterwards.

许可以下: CC-BY-SA归因
scroll top