Search code examples
randomuuidguid

What is the purpose of a UUID or GUID, compared to a random string?


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.


Solution

  • 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?