You can use random function from stdlib and fix time to maximize pseudo random operation in a short period of short time.
{
qsrand( (unsigned)time(NULL) ^random());
return qrand() % max;
}
Using qsrand(QTime::currentTime().msec()) it can also be done, but in a short period of time the function will return the same value.