If I randomly generate a string of 32 characters-long can I use this string as a GUID for all intents and purposes?
Will the "GUID" I generate have more or less likelihood of collision than a "real" GUID?
Any more specific info on GUIDs and how they compare to random strings is appreciated.
GUID-generation algorithms take into account the date and time as well as generating random numbers to create the final 128 bit value.
If you simply generate random strings w/o any other algorithmics thrown in then yes, you will run a much greater risk of collision. (Computers cannot create truly random numbers so other data has to folded into the GUID gen algorithms to lower risk of collision. GUID v1 for example used a computer's MAC address though that approach has been deprecated since it identifies the generating computer.)
You could create your own GUID value but why reinvent something that already works well?
Also, see Eric Lippert's answer as to why using a GUID is superior to using your own, home-brewed random ID generator.
A GUID is not a 32-character long string. So no, you cannot use it in place of a GUID.
Depending on the encoding, a char can be either one or two bytes, so 32 chars can be 32 bytes or 64 bytes. A GUID is 16 bytes. If you have an equivalent amount of randomness in your generator, your string will produce less chance of collision. Saying that, the chance of collision in 16 bytes is pretty unlikely as it is.
The clinch is that you have to have at least as good a generator as the Guid generator to make it worthwhile. When you do that, patent it.
Depends on the GUID you're comparing it against: nowadays most GUIDs are "Version 4", which is really just a big random number with some wasted bits. So as long as your random number generator is as good as the one used to generate the GUID, your solution is more unique.
If it's a Version 1 GUID, then it's probably more unique than a random number (assuming it's being used as expected: the system clock isn't being reset very often, the system has a network card, and the MAC address hasn't been tampered with) but most people don't use version 1 anymore because it leaks your MAC address.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With