views:

49

answers:

2

The function in COM to create a GUID (CoCreateGUID) uses a "Decentralized Uniqueness Algorithm", but my question is, what is it?

Can anybody explain?

+6  A: 

A method to generate an ID that has some guarantee to be unique without relying on any kind of coordination through a central "ID provider" (which requires a network connection and can be hard to organize). There are basically two methods for this, neither actually providing an absolute guarantee:

  1. Use a reasonably unique ID for the local machine (typically its MAC address) and add a locally unique ID (e.g. timestamp + process number + autoincrementing counter).
  2. Use a good random number generator with a good seed to generate the ID and make it long enough that collisions are too unlikely to matter.
Michael Borgwardt
+1, I just want to add that this stuff is needed so that every developer could generate ids for his classes and interfaces locally and the values he gets would never collide with values ever generated by other developers.
sharptooth
A: 

I have searched my local library and archives but I cannot find reference to the specific algorithm. But generally this type of algorithm is used to generate 128-bit GUID values that can only occur once. Using a standard random number generation algorithm does not generate true randomness. So in this case they have taken several values including :

  1. The computers Network Address
  2. The Computers clock time value
  3. Values to accommodate for Daylight Savings as well as manual changes to the system clock by the user.

By utilizing such a function the programmer can ensure that the values of GUID's are unique without having to a centralized server that tracks and generates all user GUID values.

You can read more about random number generation here

gruntled