00001 /* dlarnv.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 /* Subroutine */ int dlarnv_(integer *idist, integer *iseed, integer *n, 00017 doublereal *x) 00018 { 00019 /* System generated locals */ 00020 integer i__1, i__2, i__3; 00021 00022 /* Builtin functions */ 00023 double log(doublereal), sqrt(doublereal), cos(doublereal); 00024 00025 /* Local variables */ 00026 integer i__; 00027 doublereal u[128]; 00028 integer il, iv, il2; 00029 extern /* Subroutine */ int dlaruv_(integer *, integer *, doublereal *); 00030 00031 00032 /* -- LAPACK auxiliary routine (version 3.2) -- */ 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 /* DLARNV returns a vector of n random real numbers from a uniform or */ 00045 /* normal distribution. */ 00046 00047 /* Arguments */ 00048 /* ========= */ 00049 00050 /* IDIST (input) INTEGER */ 00051 /* Specifies the distribution of the random numbers: */ 00052 /* = 1: uniform (0,1) */ 00053 /* = 2: uniform (-1,1) */ 00054 /* = 3: normal (0,1) */ 00055 00056 /* ISEED (input/output) INTEGER array, dimension (4) */ 00057 /* On entry, the seed of the random number generator; the array */ 00058 /* elements must be between 0 and 4095, and ISEED(4) must be */ 00059 /* odd. */ 00060 /* On exit, the seed is updated. */ 00061 00062 /* N (input) INTEGER */ 00063 /* The number of random numbers to be generated. */ 00064 00065 /* X (output) DOUBLE PRECISION array, dimension (N) */ 00066 /* The generated random numbers. */ 00067 00068 /* Further Details */ 00069 /* =============== */ 00070 00071 /* This routine calls the auxiliary routine DLARUV to generate random */ 00072 /* real numbers from a uniform (0,1) distribution, in batches of up to */ 00073 /* 128 using vectorisable code. The Box-Muller method is used to */ 00074 /* transform numbers from a uniform to a normal distribution. */ 00075 00076 /* ===================================================================== */ 00077 00078 /* .. Parameters .. */ 00079 /* .. */ 00080 /* .. Local Scalars .. */ 00081 /* .. */ 00082 /* .. Local Arrays .. */ 00083 /* .. */ 00084 /* .. Intrinsic Functions .. */ 00085 /* .. */ 00086 /* .. External Subroutines .. */ 00087 /* .. */ 00088 /* .. Executable Statements .. */ 00089 00090 /* Parameter adjustments */ 00091 --x; 00092 --iseed; 00093 00094 /* Function Body */ 00095 i__1 = *n; 00096 for (iv = 1; iv <= i__1; iv += 64) { 00097 /* Computing MIN */ 00098 i__2 = 64, i__3 = *n - iv + 1; 00099 il = min(i__2,i__3); 00100 if (*idist == 3) { 00101 il2 = il << 1; 00102 } else { 00103 il2 = il; 00104 } 00105 00106 /* Call DLARUV to generate IL2 numbers from a uniform (0,1) */ 00107 /* distribution (IL2 <= LV) */ 00108 00109 dlaruv_(&iseed[1], &il2, u); 00110 00111 if (*idist == 1) { 00112 00113 /* Copy generated numbers */ 00114 00115 i__2 = il; 00116 for (i__ = 1; i__ <= i__2; ++i__) { 00117 x[iv + i__ - 1] = u[i__ - 1]; 00118 /* L10: */ 00119 } 00120 } else if (*idist == 2) { 00121 00122 /* Convert generated numbers to uniform (-1,1) distribution */ 00123 00124 i__2 = il; 00125 for (i__ = 1; i__ <= i__2; ++i__) { 00126 x[iv + i__ - 1] = u[i__ - 1] * 2. - 1.; 00127 /* L20: */ 00128 } 00129 } else if (*idist == 3) { 00130 00131 /* Convert generated numbers to normal (0,1) distribution */ 00132 00133 i__2 = il; 00134 for (i__ = 1; i__ <= i__2; ++i__) { 00135 x[iv + i__ - 1] = sqrt(log(u[(i__ << 1) - 2]) * -2.) * cos(u[( 00136 i__ << 1) - 1] * 6.2831853071795864769252867663); 00137 /* L30: */ 00138 } 00139 } 00140 /* L40: */ 00141 } 00142 return 0; 00143 00144 /* End of DLARNV */ 00145 00146 } /* dlarnv_ */