求解:srand((unsigned)time(NULL));
在rand()函数前加了srand((unsigned)time(NULL));还是得到相同的结果。系统时间太相近,那怎么样让它有所不一样呢?
void changeSchedule() { int num; srand((unsigned)time(NULL)); num=rand()%2; //随机选择一种方案 cout<<"随机选了第"<<num<<"种方案:"<<endl; switch(num) { case 0: { swap(); break; } case 1: { remap(); break; } } return; } void swap() { srand((unsigned)time(NULL)); //随机取出两处理器 while(pro1==pro2) { pro1=1+rand()%PRONUM; pro2=1+rand()%PRONUM; } if(temp1!=0 && temp2!=0) { tempp1=ran1[rand()%temp1]; tempp2=ran2[rand()%temp2]; } else changeSchedule(); return; }