Random discovery: Why the 13th Hex character of Guids is ‘4’

I noticed something strange in Sitecore; for most of my nodes (not the Sitecore node!), the 13th Hex character of the identifying GUID is ‘4’.

I had a list of about 50 of these, and my eye was drawn to the pattern. Now, I thought Guids were entirely random, except that the chance of 50 page template IDs all having a 4 at that character was infinitesimal.

Weird. Except it turns out that they’re not random. I had no idea that there are different versions of guids, or than that character defined the version of the GUID.

This requires a test, so I wrote a program to print Guid.NewGuid() a lot:

All of them are 4s.

So:

  • GUIDs aren’t entirely random.
  • They might not be very random at all, looking at some of the other GUID versions.
  • Which is why they shouldn’t be used as a source of entropy for encryption.
  • I still have things to learn.
Random discovery: Why the 13th Hex character of Guids is ‘4’

Finding GUIDs in Visual Studio Project

Sometimes it’s useful to be able to find GUIDs in your project – especially when a previous Sitecore partner has hard-coded GUIDs in various user controls and classes throughout the site.

Anyway, the regex to run in Visual studio is:
[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}

Finding GUIDs in Visual Studio Project