(c++问题)怎么不产生随机数呢?
大家看下我的代码,怎么不产生随机数了呢?
#include<iostream.h>
#include<time.h>
#include<stdlib.h>
bool judge()
{
int a,b,c;
srand(time(0));
a=rand()%6+1;
b=rand()%6+1;
c=a+b;
if(c==7||c==11)
return false;
else if(c==2||c==3||c==12)
return true;
else
{
int n;
for(n=1;n<=7;n++)
{
a=rand()%6+1;
b=rand()%6+1;
if(a+b==c)
return true;
}
}
return false;
}
int main()
{
int n,countw=0;
for(n=1;n<=12;n++)
if(judge()==true)
countw++;
cout<<"前12次赢:"<<countw<<"次。"<<endl;
for(n=1;n<=888;n++)
if(judge()==true)
countw++;
cout<<"后888次赢:"<<countw-12<<"次。"<<endl;
double k=countw/1000.0;
cout<<"前一千次赢的机会是:"<<countw/1000.0*100<<"%"<<endl;
if(k>=0.4&&k<=0.6)
cout<<"基本公平!"<<endl;
cout<<"不公平!"<<endl;
for(n=1;n<=1000;n++)
if(judge()==true)
countw++;
if(countw/2000.0>k)
cout<<"是玩的越久赢的机会越大!"<<endl;
else
cout<<"不是玩的越久赢得机会愈大!"<<endl;
return 0;
}
那位大虾解答下啊?
小弟先谢过啦!