mardi 31 mars 2015

C++ rand() why give me the same number How can i have different [duplicate]


This question already has an answer here:





if (ii == 3){//车辆只停了一个小时,有3/4的概率离场
srand((unsigned)time(NULL)*100);
int a = 1+rand() % 4;
int b = 1+rand() % 4;
int c = 1+rand() % 4;
cout << "++++3 " << a << "++++" << endl;//用作测试判断是否离场函数
cout << "++++3 " << b << "++++" << endl;
cout << "++++3 " << c << "++++" << endl;
cout << "*************" << endl;
if ((a == 1 && b == 2 && c == 3)||(a==2&&b==1&&c==3)||(a==3&&b==2&&c==1)||(a==3&&b==2&&c==1))
return true;
else
return false;
}![enter image description here][1]


just like this picture programe give me the same number ,but i need different,how can i do it.





Aucun commentaire:

Enregistrer un commentaire