手机
当前位置:查字典教程网 >编程开发 >C语言 >c语言生成随机uuid编码示例
c语言生成随机uuid编码示例
摘要:c语言生成随机uuid编码复制代码代码如下:#include#include/***CreaterandomUUID**@parambuf-...

c语言生成随机uuid编码

复制代码 代码如下:

#include <stdio.h>

#include <stdlib.h>

/**

* Create random UUID

*

* @param buf - buffer to be filled with the uuid string

*/

char *random_uuid( char buf[37] )

{

const char *c = "89ab";

char *p = buf;

int n;

for( n = 0; n < 16; ++n )

{

int b = rand()%255;

switch( n )

{

case 6:

sprintf(

p,

"4%x",

b%15 );

break;

case 8:

sprintf(

p,

"%c%x",

c[rand()%strlen( c )],

b%15 );

break;

default:

sprintf(

p,

"%02x",

b );

break;

}

p += 2;

switch( n )

{

case 3:

case 5:

case 7:

case 9:

*p++ = '-';

break;

}

}

*p = 0;

return buf;

}

【c语言生成随机uuid编码示例】相关文章:

c语言内存泄露示例解析

c语言实现二叉查找树实例方法

C语言中打印特殊图案的实现代码

c语言全盘搜索指定文件的实例代码

C语言程序设计50例(经典收藏)

生成随机数rand函数的用法详解

C语言 扩展欧几里得算法代码

c语言常见图片格式判断实例

C语言小程序 数组操作示例代码

C 语言基础教程(一)颜色加亮

精品推荐
分类导航