-
-
Save foxoman/1f091f684753d343188d3dc7159eac27 to your computer and use it in GitHub Desktop.
Random number in Qt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QGlobal.h> | |
#include <QTime> | |
int QMyClass::randInt(int low, int high) | |
{ | |
// Random number between low and high | |
return qrand() % ((high + 1) - low) + low; | |
} | |
// Create seed for the random | |
// That is needed only once on application startup | |
QTime time = QTime::currentTime(); | |
qsrand((uint)time.msec()); | |
//qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
// Get random value between 0-100 | |
int randomValue = randInt(0,100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment