kusano 7d535a
/*  -- translated by f2c (version 19940927).
kusano 7d535a
   You must link the resulting object file with the libraries:
kusano 7d535a
	-lf2c -lm   (in that order)
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
#include "f2c.h"
kusano 7d535a
kusano 7d535a
/* Complex */ VOID clarnd_(complex * ret_val, integer *idist, integer *iseed)
kusano 7d535a
{
kusano 7d535a
    /* System generated locals */
kusano 7d535a
    doublereal d__1, d__2;
kusano 7d535a
    complex q__1, q__2, q__3;
kusano 7d535a
kusano 7d535a
    /* Builtin functions */
kusano 7d535a
    double log(doublereal), sqrt(doublereal);
kusano 7d535a
    void c_exp(complex *, complex *);
kusano 7d535a
kusano 7d535a
    /* Local variables */
kusano 7d535a
    static real t1, t2;
kusano 7d535a
    extern doublereal slaran_(integer *);
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*  -- LAPACK auxiliary routine (version 2.0) --   
kusano 7d535a
       Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,   
kusano 7d535a
       Courant Institute, Argonne National Lab, and Rice University   
kusano 7d535a
       September 30, 1994   
kusano 7d535a
kusano 7d535a
kusano 7d535a
    Purpose   
kusano 7d535a
    =======   
kusano 7d535a
kusano 7d535a
    CLARND returns a random complex number from a uniform or normal   
kusano 7d535a
    distribution.   
kusano 7d535a
kusano 7d535a
    Arguments   
kusano 7d535a
    =========   
kusano 7d535a
kusano 7d535a
    IDIST   (input) INTEGER   
kusano 7d535a
            Specifies the distribution of the random numbers:   
kusano 7d535a
            = 1:  real and imaginary parts each uniform (0,1)   
kusano 7d535a
            = 2:  real and imaginary parts each uniform (-1,1)   
kusano 7d535a
            = 3:  real and imaginary parts each normal (0,1)   
kusano 7d535a
            = 4:  uniformly distributed on the disc abs(z) <= 1   
kusano 7d535a
            = 5:  uniformly distributed on the circle abs(z) = 1   
kusano 7d535a
kusano 7d535a
    ISEED   (input/output) INTEGER array, dimension (4)   
kusano 7d535a
            On entry, the seed of the random number generator; the array 
kusano 7d535a
  
kusano 7d535a
            elements must be between 0 and 4095, and ISEED(4) must be   
kusano 7d535a
            odd.   
kusano 7d535a
            On exit, the seed is updated.   
kusano 7d535a
kusano 7d535a
    Further Details   
kusano 7d535a
    ===============   
kusano 7d535a
kusano 7d535a
    This routine calls the auxiliary routine SLARAN to generate a random 
kusano 7d535a
  
kusano 7d535a
    real number from a uniform (0,1) distribution. The Box-Muller method 
kusano 7d535a
  
kusano 7d535a
    is used to transform numbers from a uniform to a normal distribution. 
kusano 7d535a
  
kusano 7d535a
kusano 7d535a
    ===================================================================== 
kusano 7d535a
  
kusano 7d535a
kusano 7d535a
kusano 7d535a
       Generate a pair of real random numbers from a uniform (0,1)   
kusano 7d535a
       distribution   
kusano 7d535a
kusano 7d535a
       Parameter adjustments */
kusano 7d535a
    --iseed;
kusano 7d535a
kusano 7d535a
    /* Function Body */
kusano 7d535a
    t1 = slaran_(&iseed[1]);
kusano 7d535a
    t2 = slaran_(&iseed[1]);
kusano 7d535a
kusano 7d535a
    if (*idist == 1) {
kusano 7d535a
kusano 7d535a
/*        real and imaginary parts each uniform (0,1) */
kusano 7d535a
kusano 7d535a
	q__1.r = t1, q__1.i = t2;
kusano 7d535a
	 ret_val->r = q__1.r,  ret_val->i = q__1.i;
kusano 7d535a
    } else if (*idist == 2) {
kusano 7d535a
kusano 7d535a
/*        real and imaginary parts each uniform (-1,1) */
kusano 7d535a
kusano 7d535a
	d__1 = t1 * 2.f - 1.f;
kusano 7d535a
	d__2 = t2 * 2.f - 1.f;
kusano 7d535a
	q__1.r = d__1, q__1.i = d__2;
kusano 7d535a
	 ret_val->r = q__1.r,  ret_val->i = q__1.i;
kusano 7d535a
    } else if (*idist == 3) {
kusano 7d535a
kusano 7d535a
/*        real and imaginary parts each normal (0,1) */
kusano 7d535a
kusano 7d535a
	d__1 = sqrt(log(t1) * -2.f);
kusano 7d535a
	d__2 = t2 * 6.2831853071795864769252867663f;
kusano 7d535a
	q__3.r = 0.f, q__3.i = d__2;
kusano 7d535a
	c_exp(&q__2, &q__3);
kusano 7d535a
	q__1.r = d__1 * q__2.r, q__1.i = d__1 * q__2.i;
kusano 7d535a
	 ret_val->r = q__1.r,  ret_val->i = q__1.i;
kusano 7d535a
    } else if (*idist == 4) {
kusano 7d535a
kusano 7d535a
/*        uniform distribution on the unit disc abs(z) <= 1 */
kusano 7d535a
kusano 7d535a
	d__1 = sqrt(t1);
kusano 7d535a
	d__2 = t2 * 6.2831853071795864769252867663f;
kusano 7d535a
	q__3.r = 0.f, q__3.i = d__2;
kusano 7d535a
	c_exp(&q__2, &q__3);
kusano 7d535a
	q__1.r = d__1 * q__2.r, q__1.i = d__1 * q__2.i;
kusano 7d535a
	 ret_val->r = q__1.r,  ret_val->i = q__1.i;
kusano 7d535a
    } else if (*idist == 5) {
kusano 7d535a
kusano 7d535a
/*        uniform distribution on the unit circle abs(z) = 1 */
kusano 7d535a
kusano 7d535a
	d__1 = t2 * 6.2831853071795864769252867663f;
kusano 7d535a
	q__2.r = 0.f, q__2.i = d__1;
kusano 7d535a
	c_exp(&q__1, &q__2);
kusano 7d535a
	 ret_val->r = q__1.r,  ret_val->i = q__1.i;
kusano 7d535a
    }
kusano 7d535a
    return ;
kusano 7d535a
kusano 7d535a
/*     End of CLARND */
kusano 7d535a
kusano 7d535a
} /* clarnd_ */
kusano 7d535a