https://bugs.kde.org/show_bug.cgi?id=362161

--- Comment #4 from Arne <gm2....@gmail.com> ---
The problem was introduced in version 5.21.0 (which cannot be selected from the
version drop-down menu above)

The function is:

int KRandom::random()
{
    static bool init = false;
    if (!init) {
        unsigned int seed;
        init = true;
        QFile urandom(QStringLiteral("/dev/urandom"));
        bool opened = urandom.open(QIODevice::ReadOnly |
QIODevice::Unbuffered);
        if (!opened || urandom.read(reinterpret_cast<char *>(&seed),
sizeof(seed)) != sizeof(seed)) {
            // No /dev/urandom... try something else.
            qsrand(getpid());
            seed = qrand() + time(0);
        }
        qsrand(seed);
    }
    return rand();
}

On first call after program load, the qrand() random number generator is seeded
by the call of qsrand(seed).
However, the value returned by KRandom::random() is obtained by calling the
rand() random  number generator, which has not been seeded, and thus returns
the same sequence of numbers after each re-start of the calling program.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to