3

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;
}
Stargateur
  • 24,473
  • 8
  • 65
  • 91
Xiaoyao
  • 103
  • 5

0 Answers0