home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-SSP.ARJ / NORNG.C < prev    next >
Encoding:
Text File  |  1984-08-29  |  872 b   |  29 lines

  1.    norng(r,p)
  2.  
  3.       /* this function generates a sequence of numbers normally       */
  4.       /* and randomly distributed over the interval -3 to 3 from      */
  5.       /* uniformly distributed random numbers by the method of linear */
  6.       /* approximation to the inverse of the accumulative             */
  7.       /* normal distribution function.                                */
  8.  
  9.       float *r,*p;
  10.  
  11.    {
  12.       int i;
  13.       float z;
  14.       static float s[5]={43.8596,11.3636,7.25689,2.891352,2.65887};
  15.       static float x[6]={-3.01,-2.0,-1.5,-1.0,-.6,0.};
  16.       static float y[6]={0.,.0228,.0668,.1357,.2743,.5};
  17.  
  18.       z = *r;
  19.       strnum(&z);
  20.       *r = z;
  21.       *p = *r;
  22.       i = 1;
  23.       if (*p > 0.5) *p = 1. - *r;
  24.       while(*p >= y[i])
  25.        i ++;
  26.       *p = ((*p - y[i-1]) * s[i-1] + x[i-1]);
  27.       if (*r >= 0.5) *p = -*p;
  28.     }
  29.