Tell me about GUIDs aka a game of chance?
Grant Hair
Posted on January 21, 2021
This should be short and sweet.
We've probably all used GUIDs (globally unique identifiers) or UUIds (universally unique identifiers) but what do they actually mean.
A GUID looks like this: F024E833-8493-4A0D-8560-0DAA2A514251
I with my limited knowledge on this subject will try to explain some stuff, probably incorrectly, but yay me for trying.
+- UUID version
|
|-|
3 7 a 6 a d 6 3 - 7 0 0 c - 4 4 0 4 - b d d 4 - 8 2 8 5 7 5 8 4 5 0 4 5
|---------------| |-------| |---|---| |-------| |-----------------------|
| | | | | |
| | | | | +- node
| | | | +- clock_seq_low
| | | +- clock_seq_hi_and_reserved
| | +- time_hi_and_version
| +- time_mid
+- time_low
I'm not even gonna try explain the above but the tl;dr; about GUIDs is:
There are 3 (main) different types of GUIDs/UUIDs (that you will probs encounter)
V1
V4
&
V5
The differences between GUID versions
v1 uses your mac address, the current date and time and a random salt (meaning if you gen 2 GUIDS on the same machine at the exact same millisecond the chance of them being the same goes from practically impossible to very small)
v4 has no inherit logic thus giving a greater degree of random-ness
v5 uses a fixed namespace UUID and an input string to generate a non random unique identifier using the SHA1 hash. v5 UUIDs are always the same given the same namespace and input string so you must as the developer maintain their unique state
C# Dev Time
If you are a C# dev like me then you'll be wondering what does
Guid.NewGuid();
give me?
Well rest assured that some blog post I read confirmed that C# Guid.NewGuid();
will give you a v4 GUID every time.
Thanks, I hope some of the above is correct 👋
Links
https://stackoverflow.com/questions/20342058/which-uuid-version-to-use
https://www.sohamkamani.com/uuid-versions-explained/
https://stackoverflow.com/questions/55823448/how-to-generate-uuid-version-4-using-c-sharp
Posted on January 21, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 26, 2024