生成随机的GUID的C代码

随手写的,生成几个GUID有用,大规模用就不好说了偷笑

/* [email protected] */
const char* newGUID()
{
    srand(time(NULL));
    static char buf[64] = {0};
    snprintf(buf, sizeof(buf) , 
            "{%08X-%04X-%04X-%04X-%04X%04X%04X}" , 
            rand()&0xffffffff,
            rand()&0xffff, 
            rand()&0xffff, 
            rand()&0xffff, 
            rand()&0xffff, rand()&0xffff, rand()&0xffff
            );
    return (const char*)buf;
}


你可能感兴趣的:(c,null)