views:

130

answers:

5

GUID are generated by the combination of numbers and characters with a hyphen.

eg) {7B156C47-05BC-4eb9-900E-89966AD1430D}

In Visual studio, we have the 'Create GUID' tool to create it. I hope the same can be created programmatically through window APIs.

How GUIDs are made to be unique? Why they don't use any special characters like #,^ etc...

Also Is it possible to design our own algorithm to create unique GUIDs?

A: 

Yes although easier to make use of someone else's e.g. Boost uuid

Mark
+2  A: 

Yes, it is possible, however you shouldn't try to reinvent the wheel without a good reason to do so. GUIDs are made unique by including elements which (statistically speaking) are very unlikely to be the same in two distinct cases, such as:

  • Current timestamp
  • The update of the system
  • The MAC address of the system
  • A random number
  • ...

Also, consider the privacy implications of GUIDs if you implement it from zero, because they contain the above data which some people deem sensitive.

Cd-MaN
+1  A: 

Just to answer this: Why they don't use any special characters like #,^ etc..

It is supposed to be a 128bit Integer. So the common representation is simple 32 Hexadecimals.

You can create also use 128 characters of 1's and 0's etc.

As for the rest of the question, wiki has good answers.

o.k.w
+1  A: 

You should create new GUID's by calling the API designed for it. In native windows land it is CoCreateGUID; in .NET land it is System.Guid.NewGuid();

John Källén
Is there any probability that the GUID created using the above API is unique?
AKN
Yes there is. I haven't ever seen two identical GUIDs generated by that API. If you wanted to ask the opposite, then yes, there's a possibility to get two identical guid's from that API. Proof: Generate 2^128+1 GUID's; You're bound to get some duplicates!
Cosmin Prund
+2  A: 

UUIDs are defined e.g. in http://www.faqs.org/rfcs/rfc4122.html. One problem with using your own algorithm to generate something like a UUID is that you could collide with other people's UUIDs. So you should definitely use somebody else's implementation if at all possible and, if not, write your own implementation of one of the standard algorithms.

mcdowella
I like this answer. But can you list out some of the 'standard algorithms' used for UUID's.
AKN
The standard algorithms are defined in the RFC referenced above. E.g. "The algorithm for generating a UUID from a name and a name space are as follows:" to pick an arbitrary (and slightly unusual) example.
mcdowella