1 //生成随机数 2 float MainWindow::generateRand(float min, float max) 3 { 4 static bool seedStatus; 5 if (!seedStatus) 6 { 7 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); 8 seedStatus = true; 9 } 10 if(min>max) 11 { 12 float temp=min; 13 min=max; 14 max=temp; 15 } 16 double diff = fabs(max-min); 17 double m1=(double)(qrand()%100)/100; 18 double retval=min+m1*diff; 19 return retval; 20 }