dlarnd.c
Go to the documentation of this file.
00001 /* dlarnd.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 doublereal dlarnd_(integer *idist, integer *iseed)
00017 {
00018     /* System generated locals */
00019     doublereal ret_val;
00020 
00021     /* Builtin functions */
00022     double log(doublereal), sqrt(doublereal), cos(doublereal);
00023 
00024     /* Local variables */
00025     doublereal t1, t2;
00026     extern doublereal dlaran_(integer *);
00027 
00028 
00029 /*  -- LAPACK auxiliary routine (version 3.1) -- */
00030 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
00031 /*     November 2006 */
00032 
00033 /*     .. Scalar Arguments .. */
00034 /*     .. */
00035 /*     .. Array Arguments .. */
00036 /*     .. */
00037 
00038 /*  Purpose */
00039 /*  ======= */
00040 
00041 /*  DLARND returns a random real number from a uniform or normal */
00042 /*  distribution. */
00043 
00044 /*  Arguments */
00045 /*  ========= */
00046 
00047 /*  IDIST   (input) INTEGER */
00048 /*          Specifies the distribution of the random numbers: */
00049 /*          = 1:  uniform (0,1) */
00050 /*          = 2:  uniform (-1,1) */
00051 /*          = 3:  normal (0,1) */
00052 
00053 /*  ISEED   (input/output) INTEGER array, dimension (4) */
00054 /*          On entry, the seed of the random number generator; the array */
00055 /*          elements must be between 0 and 4095, and ISEED(4) must be */
00056 /*          odd. */
00057 /*          On exit, the seed is updated. */
00058 
00059 /*  Further Details */
00060 /*  =============== */
00061 
00062 /*  This routine calls the auxiliary routine DLARAN to generate a random */
00063 /*  real number from a uniform (0,1) distribution. The Box-Muller method */
00064 /*  is used to transform numbers from a uniform to a normal distribution. */
00065 
00066 /*  ===================================================================== */
00067 
00068 /*     .. Parameters .. */
00069 /*     .. */
00070 /*     .. Local Scalars .. */
00071 /*     .. */
00072 /*     .. External Functions .. */
00073 /*     .. */
00074 /*     .. Intrinsic Functions .. */
00075 /*     .. */
00076 /*     .. Executable Statements .. */
00077 
00078 /*     Generate a real random number from a uniform (0,1) distribution */
00079 
00080     /* Parameter adjustments */
00081     --iseed;
00082 
00083     /* Function Body */
00084     t1 = dlaran_(&iseed[1]);
00085 
00086     if (*idist == 1) {
00087 
00088 /*        uniform (0,1) */
00089 
00090         ret_val = t1;
00091     } else if (*idist == 2) {
00092 
00093 /*        uniform (-1,1) */
00094 
00095         ret_val = t1 * 2. - 1.;
00096     } else if (*idist == 3) {
00097 
00098 /*        normal (0,1) */
00099 
00100         t2 = dlaran_(&iseed[1]);
00101         ret_val = sqrt(log(t1) * -2.) * cos(t2 * 
00102                 6.2831853071795864769252867663);
00103     }
00104     return ret_val;
00105 
00106 /*     End of DLARND */
00107 
00108 } /* dlarnd_ */


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:46