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’

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.