Reputation: 423
Since they contain dashes and only hexadecimal characters, wouldn't random strings (incl. special characters) have way more possible combinations?
I know them being a standard is an advantage, but you could also decide to use random strings of N characters and certain whitelisted characters to prevent different formats over systems.
Upvotes: 6
Views: 4326
Reputation: 2154
UUIDs are 128-bit integers, and while a few of the bits are reserved, for all practical purposes the 122 random bits of UUIDv4 are just as good as 128 fully random bits. Other UUID types are deliberately not random because sometimes that's not what you want, and those reserved bits keep the different types from colliding because sometimes you do t care which type is used.
The common hex form is just a human-friendly representatios at the cost of taking up over twice as much space. You shouldnt use it for things that humans won't see; just store the binary form and convert as needed.
Upvotes: 2
Reputation: 76
You basically answered your own question. When fronted with the dilemma "roll your own" or use whats out there - choosing the first should be a result of careful consideration. But to answer your question, any well generated 128bit sequence will pretty much be guaranteed to be unique, so the main benefit comes from the tools available for working with UUIDs and their recognition globally for being a decent non sequential identifier.
Also, if you have time, have a look at this: Is a GUID unique 100% of the time?
Upvotes: 4