Reputation: 66112
I'm wondering if UUIDs are unique even when they are generated on different systems, which may employ different algorithms. For instance, if you generated a bunch of UUIDs in MySQL, and .Net, would there be a higher chance of collision, or are all systems using the exact same algorithm, and thereby guaranteeing that collisions are improbable?
Upvotes: 16
Views: 6079
Reputation: 21795
No, it can vary. Basically, the chance of a collision depends on the amount of entropy (="true" unpredictability) in the UUID generation method.
(a) there are different standard formats of UUID, each of which intrinsically have varying amounts of entropy (e.g. if you base your UUID on a Mac and timestamp, this in principle has less entropy than basing your UUID simply on a string of random bits)
(b) for Type 4, based on random bits, there's no standard random number generation algorithm/standard entropy source.
If you have a "perfect" random number generator, then a random UUID has 2^116 possible values (12 bits are wasted on version markers etc), in other words you would expect to generate around 2^56 or 7x10^16 UUIDs before getting a collision.
Upvotes: 2
Reputation: 5052
Given the 128 bits, there are 340,282,366,920,938,463,463,374,607,431,768,211,456 possible UUIDs. The theory is that this should be enough for them to be universally unique--so the short answer to your question is yes, even if different systems use other versions of the algorithm.
Take a look at the tables on the wiki article for a good idea of the collision probability.
Upvotes: 2
Reputation: 12129
A UUID is supposed to contain a timestamp and a version number but the rest is supposed to be random, so unless you are sure that the UUIDs are generated at different times, you run the same chances of having a collision whatever the generator software. Older versions of the generation algorithms included the MAC address, which helped to the extent of MAC address collision risks. This is all specified in RFC 4122.
Upvotes: 3
Reputation: 11703
From Universally unique identifier on Wikipedia: ..the word unique should be taken to mean "practically unique" rather than "guaranteed unique". Since the identifiers have a finite size it is possible for two differing items to share the same identifier. The identifier size and generation process need to be selected so as make this practically impossible.
Upvotes: 6