校园恋爱养成手机游戏:c++如何才很短的时间内取随机数?

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 20:55:34
for (s=0;s<5;s++)
{
//srand(time(0));
i= rand() %5 ; //产生随机数
cout << i <<endl;
//cout << time(0) <<endl;
}
就像上面 因为时间太短 再循环中time()产生的值不变 所以不行
proccess.cpp(75) : error C2065: 'randomize' : undeclared identifier
在VC++中 提示
我+了头文件

srand只需要使用一次即可,将其提到for循环外即可以产生了。

srand(time(0));
for (s=0;s<5;s++)
{
i= rand() %5 ; //产生随机数
cout << i <<endl;
}

http://zhidao.baidu.com/question/8236829.html