本篇是srand()和rand()生成随机数的姐妹篇,着重在生成0到1之间的随机数,关于具体怎么生成的随机数解释可以参看srand()和rand()生成随机数博文。
#include <iostream>
#include <time.h>
using namespace std;
void main()
{
srand(time(0));
cout << rand()%100/(double)101<<endl;
system("pause");
}
参考的资料:
C++如何产生0到1之间的随机数