zlarnd.c
Go to the documentation of this file.
00001 /* zlarnd.f -- translated by f2c (version 20061008).
00002    You must link the resulting object file with libf2c:
00003         on Microsoft Windows system, link with libf2c.lib;
00004         on Linux or Unix systems, link with .../path/to/libf2c.a -lm
00005         or, if you install libf2c.a in a standard place, with -lf2c -lm
00006         -- in that order, at the end of the command line, as in
00007                 cc *.o -lf2c -lm
00008         Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
00009 
00010                 http://www.netlib.org/f2c/libf2c.zip
00011 */
00012 
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015 
00016 /* Double Complex */ VOID zlarnd_(doublecomplex * ret_val, integer *idist, 
00017         integer *iseed)
00018 {
00019     /* System generated locals */
00020     doublereal d__1, d__2;
00021     doublecomplex z__1, z__2, z__3;
00022 
00023     /* Builtin functions */
00024     double log(doublereal), sqrt(doublereal);
00025     void z_exp(doublecomplex *, doublecomplex *);
00026 
00027     /* Local variables */
00028     doublereal t1, t2;
00029     extern doublereal dlaran_(integer *);
00030 
00031 
00032 /*  -- LAPACK auxiliary routine (version 3.1) -- */
00033 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00034 /*     November 2006 */
00035 
00036 /*     .. Scalar Arguments .. */
00037 /*     .. */
00038 /*     .. Array Arguments .. */
00039 /*     .. */
00040 
00041 /*  Purpose */
00042 /*  ======= */
00043 
00044 /*  ZLARND returns a random complex number from a uniform or normal */
00045 /*  distribution. */
00046 
00047 /*  Arguments */
00048 /*  ========= */
00049 
00050 /*  IDIST   (input) INTEGER */
00051 /*          Specifies the distribution of the random numbers: */
00052 /*          = 1:  real and imaginary parts each uniform (0,1) */
00053 /*          = 2:  real and imaginary parts each uniform (-1,1) */
00054 /*          = 3:  real and imaginary parts each normal (0,1) */
00055 /*          = 4:  uniformly distributed on the disc abs(z) <= 1 */
00056 /*          = 5:  uniformly distributed on the circle abs(z) = 1 */
00057 
00058 /*  ISEED   (input/output) INTEGER array, dimension (4) */
00059 /*          On entry, the seed of the random number generator; the array */
00060 /*          elements must be between 0 and 4095, and ISEED(4) must be */
00061 /*          odd. */
00062 /*          On exit, the seed is updated. */
00063 
00064 /*  Further Details */
00065 /*  =============== */
00066 
00067 /*  This routine calls the auxiliary routine DLARAN to generate a random */
00068 /*  real number from a uniform (0,1) distribution. The Box-Muller method */
00069 /*  is used to transform numbers from a uniform to a normal distribution. */
00070 
00071 /*  ===================================================================== */
00072 
00073 /*     .. Parameters .. */
00074 /*     .. */
00075 /*     .. Local Scalars .. */
00076 /*     .. */
00077 /*     .. External Functions .. */
00078 /*     .. */
00079 /*     .. Intrinsic Functions .. */
00080 /*     .. */
00081 /*     .. Executable Statements .. */
00082 
00083 /*     Generate a pair of real random numbers from a uniform (0,1) */
00084 /*     distribution */
00085 
00086     /* Parameter adjustments */
00087     --iseed;
00088 
00089     /* Function Body */
00090     t1 = dlaran_(&iseed[1]);
00091     t2 = dlaran_(&iseed[1]);
00092 
00093     if (*idist == 1) {
00094 
00095 /*        real and imaginary parts each uniform (0,1) */
00096 
00097         z__1.r = t1, z__1.i = t2;
00098          ret_val->r = z__1.r,  ret_val->i = z__1.i;
00099     } else if (*idist == 2) {
00100 
00101 /*        real and imaginary parts each uniform (-1,1) */
00102 
00103         d__1 = t1 * 2. - 1.;
00104         d__2 = t2 * 2. - 1.;
00105         z__1.r = d__1, z__1.i = d__2;
00106          ret_val->r = z__1.r,  ret_val->i = z__1.i;
00107     } else if (*idist == 3) {
00108 
00109 /*        real and imaginary parts each normal (0,1) */
00110 
00111         d__1 = sqrt(log(t1) * -2.);
00112         d__2 = t2 * 6.2831853071795864769252867663;
00113         z__3.r = 0., z__3.i = d__2;
00114         z_exp(&z__2, &z__3);
00115         z__1.r = d__1 * z__2.r, z__1.i = d__1 * z__2.i;
00116          ret_val->r = z__1.r,  ret_val->i = z__1.i;
00117     } else if (*idist == 4) {
00118 
00119 /*        uniform distribution on the unit disc abs(z) <= 1 */
00120 
00121         d__1 = sqrt(t1);
00122         d__2 = t2 * 6.2831853071795864769252867663;
00123         z__3.r = 0., z__3.i = d__2;
00124         z_exp(&z__2, &z__3);
00125         z__1.r = d__1 * z__2.r, z__1.i = d__1 * z__2.i;
00126          ret_val->r = z__1.r,  ret_val->i = z__1.i;
00127     } else if (*idist == 5) {
00128 
00129 /*        uniform distribution on the unit circle abs(z) = 1 */
00130 
00131         d__1 = t2 * 6.2831853071795864769252867663;
00132         z__2.r = 0., z__2.i = d__1;
00133         z_exp(&z__1, &z__2);
00134          ret_val->r = z__1.r,  ret_val->i = z__1.i;
00135     }
00136     return ;
00137 
00138 /*     End of ZLARND */
00139 
00140 } /* zlarnd_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:56:41