33,008
社区成员
发帖
与我相关
我的任务
分享
double res = (rand()+0.0)/MAX;//产生0到1的随机数
if(res<=0.5)function1;
#include <stdio.h>
#include <iostream>
#include <time.h>
using namespace std;
#define MAX 100.0
int main(int argc, char* argv[])
{
srand( (unsigned)time( NULL ) );//srand()函数产生一个以当前时间开始的随机种子
for (int i=0;i<100;i++)
{
double res = (rand()+0.0)/MAX;//产生0到1的随机数
if(res<=0.5)function1;
else if(res<=0.5+0.2)function2;
else if(res <= 0.5+0.2+0.2) function3;
}
return 0;
}