VMc*_*ron 15
我错过了什么吗?你不能:
cat /proc/sys/kernel/random/uuid
Run Code Online (Sandbox Code Playgroud)
谢谢你们的评论!
我经历了每一个,这是最符合我要求的:
我需要的只是简单的基于时间的UUID,它是由安装应用程序的每个用户的随机数生成的.RFC 4122中指定的UUID版本4就是它.我完成了一个建议的算法,并提出了一个非常简单的解决方案,可以在Linux和Windows中使用(也许它太简单了,但它确实满足了需要!):
srand(time(NULL));
sprintf(strUuid, "%x%x-%x-%x-%x-%x%x%x",
rand(), rand(), // Generates a 64-bit Hex number
rand(), // Generates a 32-bit Hex number
((rand() & 0x0fff) | 0x4000), // Generates a 32-bit Hex number of the form 4xxx (4 indicates the UUID version)
rand() % 0x3fff + 0x8000, // Generates a 32-bit Hex number in the range [0x8000, 0xbfff]
rand(), rand(), rand()); // Generates a 96-bit Hex number
Run Code Online (Sandbox Code Playgroud)
我找到的一个好方法(对于linux dev)是#include <uuid/uuid.h>
.然后你可以调用一些函数:
void uuid_generate(uuid_t out);
void uuid_generate_random(uuid_t out);
Run Code Online (Sandbox Code Playgroud)