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

posted @ 2018-06-01 23:40  findumars  Views(36628)  Comments(0Edit  收藏  举报