1肥矢、生成一定范圍內(nèi)的隨機(jī)數(shù)
/*
* 生成 [ 0 - nMax ]范圍內(nèi)不重復(fù)的數(shù)據(jù) nCount 個
* 注意端衰, nMax 不小于 nCount
*
*/
QList<int> random(int nMax, int nCount)
{
QList<int> intList;
int i=0, m=0;
QTime time;
for(i=0;;)
{
if (intList.count() > nCount)
break;
int randn;
time = QTime::currentTime();
qsrand(time.msec()*qrand()*qrand()*qrand()*qrand()*qrand()*qrand());
randn = qrand()%nMax;
m=0;
while(m<i && intList.at(m)!=randn)
m++;
if(m==i) { intList.append(randn); i++;}
else if(i==nMax) break;
else continue;
}
return intList;
}