Do you notice anything odd about the following list?
00000000-9b6d-4998-9dd7-6026894bdfba
11111111-9022-4400-bac2-8b66a9874443
22222222-a890-4dec-98bc-f41536b760bc
33333333-e361-4239-8d04-3f16f68ad9ce
44444444-d8c2-40ab-91bd-5a84511ed9d3
55555555-447a-4aa9-a51f-35c74a154156
66666666-193b-4ac3-bd92-860b6b49aedb
77777777-49de-4cc5-b9e6-2e5785dd47af
88888888-0d00-4672-933a-d68e240772be
99999999-7d9d-4d77-9e35-5e919db0f7d1
aaaaaaaa-76cd-4d6b-bae2-574e5b57c7ab
bbbbbbbb-6f9e-4d2d-ba11-64df5c7355fa
cccccccc-b897-4b15-9ab3-11b97836ce85
dddddddd-b417-48ad-8b5b-b762df75e03b
eeeeeeee-cc9c-4cb8-bae0-bbd4b10307fa
ffffffff-8d46-4a31-b297-2ac67dda3600
Yes, they are all legitimate Guids (Globally Unique IDs). But each is also a Vanity Guid, which is a unique ID that has some recognizable pattern embedded in the Guid’s text representation. A Vanity Guid is like a vanity license plate, only geekier. You can use Vanity Guids for:
- Branded software (e.g., your company or product ID)
- Debugging (e.g., easily spot a specific Guid in a running program or long list of IDs)
- Geek humor or insults
So how do you make a Vanity Guid? Answer: The brute force (and easy) way is to create billions of Guids until you find one that meets your desired pattern.
But why not just manually create whatever Guid you want, such as aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa? Answer: With a manual approach, you cannot guarantee the Guid is globally-unique.
In addition to obvious patterns, you can also embed words in Vanity Guids. Of course, with a Guid you’re limited to hexadecimal digits (0-9,A-F). But you can be creative and substitute numbers for letters, such as:
babeface-81f0-4a99-9e10-3ba203c54f4e
badb100d-0ea7-4208-bce9-043bb590e2c2
b19b00b5-3772-4a86-aece-0fe19729adf0
Following is a simple console program that generates Vanity Guids whose first block contains all the same character, as shown in the list at top. The list is written to a text file and then opened in Notepad.
using System; using System.Diagnostics; using System.IO; using System.Text; namespace CSharp411 { class Program { static void Main( string[] args ) { StringBuilder sb = new StringBuilder(); int count = 0; while (count < 10) { string guid = Guid.NewGuid().ToString(); char c = guid[0]; if (c == guid[1] && c == guid[2] && c == guid[3] && c == guid[4] && c == guid[5] && c == guid[6] && c == guid[7]) { count++; sb.Append( guid ); sb.Append( "rn" ); Console.WriteLine( guid ); } } string path = @"C:tempGuids.txt"; File.WriteAllText( path, sb.ToString() ); Process.Start( "notepad.exe", path ); } } }
BTW, I modified the sample program to run until it generated the complete list shown at top (i.e., one Vanity Guid for each hex digit). It ran overnight and finished after 10 hours 36 minutes!
The other interesting thing is it generated all but 4 Guids within the first hour. Took another hour for the next 2. Then eight more hours for the final 2. The laptop fan was running all night!
Perhaps there is a programmatic way to approach this directly, i.e. create a Guid manually and instantly, while remaining globally unique. But I’ll leave that as an exercise to my smart readers. 🙂
http://www.youtube.com/watch?v=0MRmxfLuNto
You can’t guarantee that a System.Guid will be globally unique either, to the point of it being fairly pointless using the Guid class to create a few billion GUIDs just to force retrieve what is essentially a manually created one anyway
I think this article is a joke. But a Guid is mathematically likely to be globally unique, which is why it’s called a Guid. From Wikipedia:
This number is so large that the probability of the same number being generated twice is extremely small: assuming the universe is 13.75 billion years old, and that today’s fastest supercomputer (the Tianhe-1A) at 2.5 petaflops could generate 2.5×1015 random GUIDs every second, if it had been dedicated exclusively to this task nonstop since the Big Bang, it still would have odds of less than one in 300,000 of ever having generated a duplicate.
How about you generate a couple of guids and replace some of its characters with what you want? I’lld think the chances of those guids being unique are the same as those of the ones your code generates.
The uniqueness of manually-generated GUIDs drops drastically and cannot be guaranteed. Though this is a theoretical article just for fun, one should never manually generate an ID and expect it to be unique.