首页上一页 1 下一页尾页 2 条记录 1/1页
求教!!!
提一下srand()函数这么用:
srand(time(NULL));//生成随机种子,也就是随机变量的值随着系统时间变化
取随机数是使用rand()函数,这么用:
a = rand()//我们假设有变量a
取范围内的随机数,这么用:
a = rand()%x+1//表示从1-x的范围内取一个随机数
#include<iostream>
#include<ctime.h>//要使用time()函数
using namespace std;
int main()
{
srand(time(NULL));
int a;
int x=11;
cout<<rand()%x+1;
return 0;
}(以上根据个人经验回答,如有不标准请参考书上)