home *** CD-ROM | disk | FTP | other *** search
- porng(l,max,iflag,r,y,s,x)
-
- /* this function generates a sequence of random numbers from */
- /* uniformly distributed random numbers by the method of linear */
- /* approximation of the inverse of the accumulative Poisson */
- /* distribution function. */
-
- int iflag,l,max;
- float *r,*x,s[],y[];
-
- {
- int i,n;
- float e,r1,xl,z;
- extern double pow();
-
- if (iflag != 0)
- {
- e = .367879;
- iflag = 0;
- y[0] = 0.0;
- xl = l;
- z = pow(e,xl);
- n = max - 1;
- y[max] = 1.0;
-
- for(i = 1; i <= n; i++)
- {
- y[i] = y[i-1] + z;
- s[i-1] = y[i] - y[i-1];
- z = z * xl / i;
- }
- s[max-1] = 1. - y[max-1];
- }
- r1 = *r;
- strnum(&r1);
- *r = r1;
- for(i = 1; i <= max; i++)
- if(*r <= y[i]) break;
- *x = (*r - y[i-1])/s[i-1] + i;
- }