Solaris 上的 uuid_generate_random (libuuid)
我有一个简单的 C++ 函数,调用“uuid_generate_random”。生成的 UUID 似乎不符合标准(UUID 版本 4)。有什么想法吗?
我使用的代码是(uuid_generate_random & uuid_unparse 函数在 libuuid 中可用):
char uuidBuff[36];
uuid_t uuidGenerated;
uuid_generate_random(uuidGenerated);
uuid_unparse(uuidGenerated, uuidBuff);
我知道“uuid_generate_random”生成 UUID 版本 4,但是,返回的字符串类似于:
Run1) 2e9dc3c5-426a-eea0-8186-f6b65b5dc361
Run2) 112c6a78-51bc-cbbb-ae9c-92a33e1fd95f
Run3) 5abd3d6d-0259-ce5c-8428-a51bacc04c0f
Run4) 66a22485-7e5f-e5c2-a317-c1b295bf124f
它似乎正在返回随机字符整个字符串。根据维基百科的定义,其格式应为:
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx,其中 x 可以是任何十六进制数字,但 y 只能是 8、9、A 或 B 之一。
任何意见将不胜感激。
问候 丹尼尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你说的很对,libuuid 似乎没有遵守 ITU 建议...可以说,该建议本身在保留版本信息方面过于迂腐,因为除了允许技术人员轻松区分 UUID 的方式之外,它没有什么用处。生成了,但这不是重点。
好消息是,如果您愿意,您可以通过粉碎正确版本位的简单权宜之计轻松地将它们变成一致的 UUID。 :-)
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. :-)