第一种方法

[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

相关文章:

  • 2022-01-06
  • 2022-02-17
  • 2021-12-18
  • 2022-02-28
  • 2022-12-23
  • 2022-02-20
  • 2021-09-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2021-12-18
  • 1970-01-01
  • 2021-12-04
相关资源
相似解决方案