Qt产生随机数(两种方法)

第一种方法

[cpp] view plain copy
 
  1. #include <QTime>  
[cpp] view plain copy
 
  1. QTime time;  
  2. time= QTime::currentTime();  
  3. qsrand(time.msec()+time.second()*1000);  
  4. int n = qrand() % 5;    //产生5以内的随机数  

第二种方法

[cpp] view plain copy
 
  1. #include <ctime>  
[cpp] view plain copy
 
  1. qsrand(time(NULL));  
  2. int n = qrand() % 5;    //产生5以内的随机数  

https://blog.csdn.net/graceland525/article/details/51941076

原文地址:https://www.cnblogs.com/findumars/p/9124087.html