参考:http://www.bolenot.ru/library/cmd/blcmdl3_uuid_generate_random.htm
char *psz_buf = malloc( 64 );
if ( !psz_buf )
return NULL;
uuid_t uu;
uuid_generate_random( uu );
uuid_unparse_upper( uu, psz_buf );
uuid_generate_random功能强制使用的所有随机UUID格式,高质量的随机数发生器(例如,/ dev / urandom的 ),即使是不提供的,在这种情况下,伪随机发生器将被换掉。 需要注意的是一个伪随机数发生器的使用可能危及以这种方式产生的UUID的唯一性。
uuid_generate_time功能强制使用的替代算法,它使用当前的时间和本地以太网的MAC地址(如果可用)。 该算法使用的是默认的用于生成的UUID,但因为使用的以太网MAC地址,它可以泄漏约在何时何地产生的UUID的信息。 这可能会导致在某些应用中的隐私问题,因此,uuid_generate功能只使用该算法的随机性高品质的来源无法使用。
UUID是16字节(128位),从而使约3.4x10 ^ 38(根据卡尔·萨根的宇宙,有大约10 ^ 80宇宙elemntary的粒子)独特的价值观。 可以合理地被视为新的UUID,其中在本地系统上创建的所有独特的UUID,在过去和未来之间的其他系统上创建的UUID。
SYNOPSIS #include <uuid/uuid.h> void uuid_unparse(uuid_t uu, uuid_string_t out); void uuid_unparse_lower(uuid_t uu, uuid_string_t out); void uuid_unparse_upper(uuid_t uu, uuid_string_t out); DESCRIPTIONSYNOPSIS #include <uuid/uuid.h> void uuid_unparse(uuid_t uu, uuid_string_t out); void uuid_unparse_lower(uuid_t uu, uuid_string_t out); void uuid_unparse_upper(uuid_t uu, uuid_string_t out); DESCRIPTION The uuid_unparse function converts the supplied UUID uu from the binary representation into a uuid_string_t (37-byte string including tailing '\0') of the form 1b4e28ba-2fa1-11d2-883f-b9a761bde3fb and stores this value in the character string pointed to by out. The case of the hex digits returned by uuid_unparse may be upper or lower case, and is dependent on the system-dependent local default. If the case of the hex digits is important then the functions uuid_unparse_upper and uuid_unparse_lower may be used.