void uuid4_string_generate()

in common/uuid4.cpp [165:206]


void uuid4_string_generate(char *dst)
{
    static int init_flg = 0;
    if (init_flg == 0) {
        if (uuid4_init() != 0) printf("uuid init error.\n");
        init_flg = 1;
    }
    static const char *uuid4_template = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
    static const char *chars = "0123456789abcdef";
    union {
        unsigned char b[16];
        uint64_t word[2];
    } s;
    const char *p;
    int i, n;
    /* get random */
    s.word[0] = xorshift128plus(seed);
    s.word[1] = xorshift128plus(seed);
    /* build string */
    p = uuid4_template;
    i = 0;
    while (*p)
    {
        n = s.b[i >> 1];
        n = (i & 1) ? (n >> 4) : (n & 0xf);
        switch (*p)
        {
        case 'x':
            *dst = chars[n];
            i++;
            break;
        case 'y':
            *dst = chars[(n & 0x3) + 8];
            i++;
            break;
        default:
            *dst = *p;
        }
        dst++, p++;
    }
    *dst = '\0';
}