Last active
May 27, 2019 19:14
-
-
Save johanvergeer/7206ed44b09a8cc0c2a49f32ee8c3b40 to your computer and use it in GitHub Desktop.
Check for 10 million Guids whether they are a UUID version 4. This Gist is used in my blog post https://johanvergeer.github.io/posts/net-guid-uuid-version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
˅ | |
37a6ad63-700c-4404-bdd4-828575845045 | |
b0f9f119-c667-4af7-b50c-f354e2cc235b | |
3553da71-f02c-49c9-8a0e-36c8d921d6ad | |
57fa71f7-846b-4cc1-9ccb-6849e3b473de | |
d83e2e66-43b6-4021-8950-7825bea500b0 | |
95d94be0-7ea7-49a0-a19a-22d504d99ce9 | |
68128afd-7c82-4012-8b3c-9f56a75c7628 | |
cae534a0-cb29-4d22-a16c-70f764aedbcb | |
214f5a04-fbaf-4cbf-9342-ac1191ed3d27 | |
a87969e6-7390-4164-a624-fe3327be1fa6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Simple script to check whether a C# Guid is really a UUID version 4. | |
/// </summary> | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine($"{"Current",-10}{"Errors found",-10}"); | |
Console.WriteLine($"{"-------",-10}{"------------",-10}"); | |
var errorsFound = 0; | |
for (var i = 0; i < 10_000_000; i++) | |
{ | |
var guid = Guid.NewGuid(); | |
var uuidVersion = guid.ToString().Substring(14, 1); | |
var isVersion4 = uuidVersion == "4"; | |
if (!isVersion4) | |
{ | |
errorsFound += 1; | |
} | |
Console.Write($"\r{i, -10}{errorsFound, -10} "); | |
} | |
Console.WriteLine(); | |
Console.ReadKey(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Current Errors found | |
------- ------------ | |
9999999 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+- 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment