源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c语言生成随机uuid编码示例

  • 时间:2022-04-25 14:39 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c语言生成随机uuid编码示例
c语言生成随机uuid编码
[u]复制代码[/u] 代码如下:
#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 );                 break;             case 8:                 sprintf(                     p,                     "%c%x",                     c[rand()%strlen( c )],                     b );                 break;             default:                 sprintf(                     p,                     "x",                     b );                 break;         }         p += 2;         switch( n )         {             case 3:             case 5:             case 7:             case 9:                 *p++ = '-';                 break;         }     }     *p = 0;     return buf; }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部