mardi 9 octobre 2018

In (rand() >> 7) & 0xFF, what is the significance of rand() >> 7? [duplicate]

This question already has an answer here:

The context source code is belong to libuuid-1.0.3 randutils.c, what is the significance in rand() >> 7. I think it is not necessary.

void random_get_bytes(void *buf, size_t nbytes)
{
    size_t i, n = nbytes;
    int fd = random_get_fd();
    int lose_counter = 0;
    unsigned char *cp = (unsigned char *) buf;

    if (fd >= 0) {
        while (n > 0) {
            ssize_t x = read(fd, cp, n);
            if (x <= 0) {
                if (lose_counter++ > 16)
                    break;
                continue;
            }
            n -= x;
            cp += x;
            lose_counter = 0;
        }

        close(fd);
    }


    for (cp = buf, i = 0; i < nbytes; i++)
        *cp++ ^= (rand() >> 7) & 0xFF;

    ...

    return;
}




Aucun commentaire:

Enregistrer un commentaire