c語言生成隨機uuid編碼示例
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;
}
相關(guān)文章
QT實戰(zhàn)之實現(xiàn)圖片瀏覽系統(tǒng)
這篇文章主要介紹了如何利用QT編寫一個圖片瀏覽系統(tǒng),可以支持自動播放,左右拖動切換,點擊列表切換,點擊按鈕切換等功能,感興趣的小伙伴可以跟隨小編一起了解一下2023-04-04C++中回調(diào)函數(shù)及函數(shù)指針的實例詳解
這篇文章主要介紹了C++中回調(diào)函數(shù)及函數(shù)指針的實例詳解的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下2017-10-10