关于随机数的问题
#include<stdio.h>#include<math.h>
#include<time.h>
#include<stdlib.h>
#define P_num 30
#define dm 160
double particle[P_num][dm];
void main()
{
void initial();
int i,j;
srand((unsigned)time(NULL));
initial();
for(j=0;j<dm;j++)
printf("%f\n",particle[2][j]);
}
void initial()
{
int a[160]={0,40,52,76,88,112,124,164,
40,80,92,116,128,152,164,204,
80,120,132,156,168,192,204,244,
120,160,172,196,208,232,244,284,
160,200,212,236,248,272,284,324,
200,240,252,276,288,312,324,364,
240,280,292,316,328,352,364,404,
280,320,332,356,368,392,404,444,
320,360,372,396,408,432,444,484,
360,400,412,436,448,472,484,524,
400,440,452,476,488,512,524,564,
440,480,492,516,528,552,564,604,
480,520,532,556,568,592,604,644,
520,560,572,596,608,632,644,684,
560,600,612,636,648,672,684,724,
600,640,652,676,688,712,724,764,
640,680,692,716,728,752,764,804,
680,720,732,756,768,792,804,844,
720,760,772,796,808,832,844,884,
760,800,812,836,848,872,884,924};
int i,j;
double b0,b1,b2,b3,b4,b5,b6,b7;
for(j=0;j<dm;j++)
particle[0][j]=a[j];
for(i=1;i<P_num;i++)
{
while(1)
{
b0=particle[0][0];
b1=particle[0][1]+10*rand()/RAND_MAX;
b2=particle[0][2]+10*rand()/RAND_MAX;
b3=particle[0][3]+10*rand()/RAND_MAX;
b4=particle[0][4]+10*rand()/RAND_MAX;
b5=particle[0][5]+150*rand()/RAND_MAX;
b6=particle[0][6]+10*rand()/RAND_MAX;
b7=particle[0][7]+10*rand()/RAND_MAX;
if(b1-b0>42&&b1-b0<48&&b2-b1>9&&b2-b1<15&&b3-b2>24&&b3-b2<32&& b4-b3>9&&b4-b3<15&&
b5-b4>24&&b5-b4<32&&b6-b5>15&&b6-b5<20&&b7-b6>40&&b7-b6<45) break;
}
particle[i][0]=b0;
particle[i][1]=b1;
particle[i][2]=b2;
particle[i][3]=b3;
particle[i][4]=b4;
particle[i][5]=b5;
particle[i][6]=b6;
particle[i][7]=b7;
for(j=1;j<20;j++)
{
while(1)
{
b0=particle[0][8*j]+10*rand()/RAND_MAX;
b1=particle[0][8*j+1]+10*rand()/RAND_MAX;
b2=particle[0][8*j+2]+10*rand()/RAND_MAX;
b3=particle[0][8*j+3]+10*rand()/RAND_MAX;
b4=particle[0][8*j+4]+10*rand()/RAND_MAX;
b5=particle[0][8*j+5]+10*rand()/RAND_MAX;
b6=particle[0][8*j+6]+10*rand()/RAND_MAX;
b7=particle[0][8*j+7]+10*rand()/RAND_MAX;
if(b1-b0>42&&b1-b0<48&&b2-b1>9&&b2-b1<15&&b3-b2>24&&b3-b2<32&&b4-b3>9&&b4-b3<15&&b5-b4>24&&
b5-b4<32&&b6-b5>15&&b6-b5<20&&b7-b6>40&&b7-b6<50
&&b0-particle[i][8*j-7]>0&&b0-particle[i][8*j-7]<10
&&b6-particle[i][8*j-1]>0&&b6-particle[i][8*j-1]<10)
break;
}
particle[i][8*j]=b0;
particle[i][8*j+1]=b1;
particle[i][8*j+2]=b2;
particle[i][8*j+3]=b3;
particle[i][8*j+4]=b4;
particle[i][8*j+5]=b5;
particle[i][8*j+6]=b6;
particle[i][8*j+7]=b7;
}
}
}
请教一下,以上程序中随机数的用法对吗??为什么我运行的时候10*rand()/RAND_MAX总是等于一个数;根本不是随机取值。