- 利用rand()函数,产生的随机数,用来构造uuid。
- uuid格式为:
%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x
- 特别说明:
必须要加上第17行的随机种子,才能产生随机数,否则,每次调用GenerateUuid(),获取到的uuid结果都是一样的值。
#include <string.h>
#include <string>
#include "time.h"
/*
* 功能描述: 生成随机uuid
* 参数描述: uuid字符串为36个字符加结束符,字符串长度为37
*
* uuid 长度: 8 - 4 - 4 - 4 - 12
* uuid 格式:"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"
* 字符 序号: 0~3 3 4~5 5 6~7 7 8~9 9 10~15
*/
int generate_uuid(char buf[37])
{
const