第一種方法
- #include <QTime>
- QTime time;
- time= QTime::currentTime();
- qsrand(time.msec()+time.second()*1000);
- int n = qrand() % 5; //產生5以內的隨機數
第二種方法
- #include <ctime>
- qsrand(time(NULL));
- int n = qrand() % 5; //產生5以內的隨機數
https://blog.csdn.net/graceland525/article/details/51941076