uuid_generate_random (libuuid) 在 solaris [英] uuid_generate_random (libuuid) on solaris

查看:47
本文介绍了uuid_generate_random (libuuid) 在 solaris的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 C++ 函数,它调用uuid_generate_random".生成的 UUID 似乎不符合标准(UUID 版本 4).有什么想法吗?

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?

我使用的代码是(uuid_generate_random & uuid_unparse 函数在 libuuid 中可用):

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);

我知道uuid_generate_random"生成了 UUID 版本 4,但是,返回的字符串是这样的:

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,x 为任何十六进制数字,但 y 只能为 8、9、A 或 B 之一.

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

任何输入将不胜感激.

问候丹尼尔

推荐答案

你说的很对,libuuid 似乎没有遵守 ITU 的建议......可以说该建议本身在保留版本方面过于迂腐信息,因为它除了让技术人员能够轻松区分 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.

好消息是,如果您愿意,您可以通过粉碎正确版本位的简单权宜之计轻松地将这些变成符合标准的 UUID.:-)

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. :-)

这篇关于uuid_generate_random (libuuid) 在 solaris的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆