关于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;
}
第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;
}本回答被提问者采纳