tags:

views:

47

answers:

1

I have a simple C++ function that calls "uuid_generate_random". It seems the generated UUID is not standard compliant (UUID Version 4). Any Ideas?

The code I am using is (uuid_generate_random & uuid_unparse functions are available in libuuid):

char uuidBuff[36];
uuid_t uuidGenerated;
uuid_generate_random(uuidGenerated);
uuid_unparse(uuidGenerated, uuidBuff);

I understand that "uuid_generate_random" generates the UUID version 4, however, the string that is being returned is like:

Run1) 2e9dc3c5-426a-eea0-8186-f6b65b5dc361 
Run2) 112c6a78-51bc-cbbb-ae9c-92a33e1fd95f 
Run3) 5abd3d6d-0259-ce5c-8428-a51bacc04c0f 
Run4) 66a22485-7e5f-e5c2-a317-c1b295bf124f

It appears that it is returning random characters for the whole string. The definition from wikipedia, it should be in the form of:

xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx with any hexadecimal digits for x but only one of 8, 9, A, or B for y.

Any input will be greatly appreciated.

Regards Daniel

A: 

You're quite correct that libuuid seems not to be adhering to the ITU recommendation... It could be argued that the recommendation itself is overly pedantic about retaining version information, as it serves little purpose beyond allowing technorati to easily distinguish how the UUID was generated, but that's beside the point.

The good news is that, if you care to, you can easily make these into conformant UUIDs through the simple expedient of smashing in the right version bits. :-)

Kaelin Colclasure
Thanks for the quick reply! I was thinking of "smashing" the version bits too... a bit of a hack but...
Daniel