11智能在线
新记
关于C++中的random函数
VC++6中是不是没有random这个函数啊要是没有我要产生1到6中的随机
举报该文章
其他看法
第1个回答 2009-05-07
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
srand((unsigned)time(NULL));
cout<<rand()%6+1<<endl;
return 0;
}
第2个回答 2009-05-07
http://hi.baidu.com/269825369/blog/item/49fe7d25242409094d088df2.html
第3个回答 2009-05-07
int a;
a = rand()%6 + 1
第4个回答 2009-05-07
可以使用rand函数,参考代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int i, r;
srand(time(NULL));
for (i = 0; i < 20; ++i)
{
r = (rand() % 6) + 1;
printf("%d ", r);
}
return 0;
}本回答被提问者采纳
相似回答
谁能给我解释一下#define
RANDOM
(a,b) (rand()%(b+1)-(a)+(a))_百 ...
答:
C++中rand
()范围[0,RAND_MAX],注意是闭区间。我的机器上的RAND_MAX是32767。.1.生成整数随机数,a b均为整数,且a<b [a,b)---rand()%(b-a)+a [a,b] ---rand()%(b-a+1)+a (a,b) ---rand()%(b-a-1)+a+1 [a,b) ---rand()%(b-a)+a+1 记住一点:rand(...
大家正在搜
matlab中random函数
java中random函数用法
python中的format函数
matlab中rand函数
python中的range函数
c语言中random函数用法
java中的random
python中uniform函数
java中random的范围
相关问题
c++中random函数的功能有哪些 怎么用啊
C语言中Random包含在哪个函数库中
c++中的RANDOM()函数怎么使用?
C语言中 random() 函数怎么用?
有关C语言中random函数的用法
c++ <random>
C++中的随机函数怎么用?
C++随机函数怎么用