跪求:随机函数

来源:百度知道 编辑:UC知道 时间:2024/06/20 10:51:36
#include <stdlib.h>
#include <stdio.h>

void main()
{
int j, one,two,three;

randomize();
for(j=0;j<1;j++)
{
one = random(9 ) + 1;
two=random(9 ) + 1;
three=random(9 ) + 1;
printf("one:%d,two=:%d,three=:%d\n",one,two,three);
printf("************\n");
}
}

跪求::高手 帮帮忙!!
这是一个随机函数,我想把它改成;定义一个a[3][10]得数组,先给树祖数组初始化。然后在数组中进行随机.每次随机出的数不同

#include <stdlib.h>
#include <stdio.h>

void main()
{
int a[3][10]
int i,j;

randomize();

for (i=0;i<3;i++)
{
for(j=0;j<10;j++)
{
a[i][j] = random(9 ) + 1;
printf("a[%d][%d]=%d, ",i,j,a[i][j]);
}
printf("\n");
}
printf("************\n");
}
}

???你的用法像是java里的随机数,c里面应该是这样的
例: 取1-100之内的随即数
int a;
a=rand()%100+1;
这样每次随机出来的数字都一样,你在开头加上随即数的种子
srand(unsigned(time(NULL)));想使用time函数必须包含头文件time.h

往2维数组里存值很简单,2个for循环就解决了,自己好好想想,不能全靠别人.