新建Empty qmake project,命名为UseRand
UseRand.pro
SOURCES += \
main.cppQT += core
main.cpp
#include <QTime>
#include <QTextStream>const int RAND_POS = ;
const int DOT_SIZE = ;int main()
{
QTextStream out(stdout); QTime time = QTime::currentTime();
qsrand((uint) time.msec()); int r = qrand() % RAND_POS;
int x = (r * DOT_SIZE); out << RAND_POS << endl;
out << x << endl; return ;
}