In the docs, it's written:
int QRandomGenerator::bounded(int highest)
Note that this function cannot be used to obtain values in the full 32-bit range of int. Instead, use generate() and cast to int.
But generate()
returns quint32
.
So it looks like it's suggested to use static_cast<int>(QRandomGenerator::global()->generate())
and get a signed overflow and -- this way -- get a signed random 32bit integer. But is not a signed overflow an undefined behavior? Or do I understand anything wrong? What is a proper way to get a random int in Qt?