注册 登录
编程论坛 VC++/MFC

请教这段程序详解

zxleslie 发布于 2013-11-13 11:40, 369 次点击
void randa(float *x,int num)
{
  int i;
  struct time stime;
  unsigned seed;
  gettime(&stime);
  seed=stime.ti_hund*stime.ti_min*stime.ti_hour;
  srand(seed);
  for(i=0;i<num;i++)
  {
     x[i]=rand();
     x[i]=x[i]/32768;
  }
2 回复
#2
zxleslie2013-11-13 11:51
void randl(float *x, float a, float b, int num)
{
  float x1[MAX_N],x2[MAX_N];
  float temp[MAX_N];
  int i;
  struct time stime;
  unsigned seed;
  gettime(&stime);
  seed=stime.ti_hund*stime.ti_min*stime.ti_hour;
  srand(seed);
  for(i=0;i<num;i++)
  {
     x1[i]=rand();
     x2[i]=rand();
     x1[i]=x1[i]/32768;
     x2[i]=x2[i]/32768;
     temp[i]=sqrt(-2*log(x1[i]))*cos(x2[i]*M_PI);
     x2[i]=sqrt(-2*log(x1[i]))*sin(x2[i]*M_PI);
     x1[i]=temp[i];
     x[i]=sqrt((a+x1[i])*(a+x1[i])+(b+x2[i])*(b+x2[i]));
  }
#3
peach54602013-11-13 16:18
不就是求随机数嘛?
1