C语言生成随机uuid编码的代码
更新:HHH   时间:2023-1-7


如下的内容段是关于C语言生成随机uuid编码的内容。

#include <stdio.h>
#include <stdlib.h>

{
    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:
                break;
        }
    }

    return buf;
}
返回编程语言教程...