Uuid_generate_random (libuuid) on solaris

I have a simple C ++ function that calls uuid_generate_random. The generated UUID does not seem to be standard (UUID Version 4). Any ideas?

The code I use (uuid_generate_random and 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 a version of UUID 4, however the returned string looks like this:

 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 looks like it returns random characters for the entire string. The definition from Wikipedia should be in the form:

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

Any input is appreciated.

Relationship Daniel

+3
source share
1 answer

You are absolutely right that libuuid does not seem to adhere to the ITU recommendation ... It can be argued that the recommendation itself is overly pedantic with respect to storing version information, since it does not have any purpose, except that the technology can easily distinguish how the UUID was created, but this does not apply to the point.

The good news is that if you want this, you can easily make them according to the UUID through an easy way to bit the correct version. :-)

+1
source

Source: https://habr.com/ru/post/1433020/


All Articles