随机数的问题,请帮忙!! 我想随机生成100个数据,每个数据中包括high,width,long三个值。请问代码如何实现!谢谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 srand( (unsigned)time( NULL ) );int value = rand()%1000;这个1000表示随机数的范围是0~999之间 三个值都是double的就行,能不能给出代码?谢谢 ///如果我们的最大只限定为100void get(unsigned vhigh[100], unsigned vwidth[100], unsigned vlong[100], unsigned max = 500){ srand( (unsigned)time( NULL ) );///初始化随机数发生器 for(int i =0 ; i < 100; i++) { vhigh[i] = rand() / (max - 1) + 1;//这样可以防止等于零 vwidth[i] = rand() / (max - 1) + 1;//这样可以防止等于零 vlong[i] = rand() / (max - 1) + 1;//这样可以防止等于零 }} ///如果我们的最大只限定为100void get(unsigned vhigh[100], unsigned vwidth[100], unsigned vlong[100], unsigned max = 500){ srand( (unsigned)time( NULL ) );///初始化随机数发生器 for(int i =0 ; i < 100; i++) { vhigh[i] = rand() % (max - 1) + 1;//这样可以防止等于零 vwidth[i] = rand() % (max - 1) + 1;//这样可以防止等于零 vlong[i] = rand() % (max - 1) + 1;//这样可以防止等于零 }} ///如果我们的最大只限定为100void get(double vhigh[100], double vwidth[100], double vlong[100], unsigned max = 500){ srand( (unsigned)time( NULL ) );///初始化随机数发生器 for(int i =0 ; i < 100; i++) { vhigh[i] = rand() % (max - 1) + 1;//这样可以防止等于零 vwidth[i] = rand() % (max - 1) + 1;//这样可以防止等于零 vlong[i] = rand() % (max - 1) + 1;//这样可以防止等于零 }} srand( (unsigned)time( NULL ) ); typedef struct value { double width; double height; double length; }VALUE; const int count = 100; VALUE v[count]; for(int i=0; i<count; i++) { v[i].width = (rand()+1)/(float)(rand()%10+1); v[i].height = (rand()+1)/(float)(rand()%10+1); v[i].length = (rand()+1)/(float)(rand()%10+1); TRACE3("width=%.2f,height=%.2f,length=%.2f\n",v[i].width,v[i].height,v[i].length); } MSCOMM控件串口读取数据时为什么有效数据是8位? 好头疼的问题,DLL中使用MessageBox, 总是错 高分求助,请问如何检测出这种信号 请教EditBox的光标控制问题 如何使用StretchDIBits实现图片的放大缩小显示?? VC新手求教~~~~ 我想在一个按钮上显示一个图标,可运行之后为什么是按钮上是空白呢?(求助) 如何使用animateCtrl控件,播放 大家好啊。请多关照 请问谁能帮我!!! 如何取得一个字符传(中英文混合)得象素长度 如何点击Word 的保存或打开调用我自己的保存和打开对话框,而将word自己的对话框隐藏呢
int value = rand()%1000;这个1000表示随机数的范围是0~999之间
void get(unsigned vhigh[100], unsigned vwidth[100], unsigned vlong[100], unsigned max = 500)
{
srand( (unsigned)time( NULL ) );///初始化随机数发生器
for(int i =0 ; i < 100; i++)
{
vhigh[i] = rand() / (max - 1) + 1;//这样可以防止等于零
vwidth[i] = rand() / (max - 1) + 1;//这样可以防止等于零
vlong[i] = rand() / (max - 1) + 1;//这样可以防止等于零
}
}
void get(unsigned vhigh[100], unsigned vwidth[100], unsigned vlong[100], unsigned max = 500)
{
srand( (unsigned)time( NULL ) );///初始化随机数发生器
for(int i =0 ; i < 100; i++)
{
vhigh[i] = rand() % (max - 1) + 1;//这样可以防止等于零
vwidth[i] = rand() % (max - 1) + 1;//这样可以防止等于零
vlong[i] = rand() % (max - 1) + 1;//这样可以防止等于零
}
}
void get(double vhigh[100], double vwidth[100], double vlong[100], unsigned max = 500)
{
srand( (unsigned)time( NULL ) );///初始化随机数发生器
for(int i =0 ; i < 100; i++)
{
vhigh[i] = rand() % (max - 1) + 1;//这样可以防止等于零
vwidth[i] = rand() % (max - 1) + 1;//这样可以防止等于零
vlong[i] = rand() % (max - 1) + 1;//这样可以防止等于零
}
}
typedef struct value
{
double width;
double height;
double length;
}VALUE; const int count = 100;
VALUE v[count];
for(int i=0; i<count; i++)
{
v[i].width = (rand()+1)/(float)(rand()%10+1);
v[i].height = (rand()+1)/(float)(rand()%10+1);
v[i].length = (rand()+1)/(float)(rand()%10+1);
TRACE3("width=%.2f,height=%.2f,length=%.2f\n",v[i].width,v[i].height,v[i].length);
}