3 /* Subroutine */ int slarnv_(integer *idist, integer *iseed, integer *n, real
6 /* System generated locals */
7 integer i__1, i__2, i__3;
9 /* Builtin functions */
10 double log(doublereal), sqrt(doublereal), cos(doublereal);
16 extern /* Subroutine */ int slaruv_(integer *, integer *, real *);
19 /* -- LAPACK auxiliary routine (version 3.1) -- */
20 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
23 /* .. Scalar Arguments .. */
25 /* .. Array Arguments .. */
31 /* SLARNV returns a vector of n random real numbers from a uniform or */
32 /* normal distribution. */
37 /* IDIST (input) INTEGER */
38 /* Specifies the distribution of the random numbers: */
39 /* = 1: uniform (0,1) */
40 /* = 2: uniform (-1,1) */
41 /* = 3: normal (0,1) */
43 /* ISEED (input/output) INTEGER array, dimension (4) */
44 /* On entry, the seed of the random number generator; the array */
45 /* elements must be between 0 and 4095, and ISEED(4) must be */
47 /* On exit, the seed is updated. */
49 /* N (input) INTEGER */
50 /* The number of random numbers to be generated. */
52 /* X (output) REAL array, dimension (N) */
53 /* The generated random numbers. */
58 /* This routine calls the auxiliary routine SLARUV to generate random */
59 /* real numbers from a uniform (0,1) distribution, in batches of up to */
60 /* 128 using vectorisable code. The Box-Muller method is used to */
61 /* transform numbers from a uniform to a normal distribution. */
63 /* ===================================================================== */
65 /* .. Parameters .. */
67 /* .. Local Scalars .. */
69 /* .. Local Arrays .. */
71 /* .. Intrinsic Functions .. */
73 /* .. External Subroutines .. */
75 /* .. Executable Statements .. */
77 /* Parameter adjustments */
83 for (iv = 1; iv <= i__1; iv += 64) {
85 i__2 = 64, i__3 = *n - iv + 1;
93 /* Call SLARUV to generate IL2 numbers from a uniform (0,1) */
94 /* distribution (IL2 <= LV) */
96 slaruv_(&iseed[1], &il2, u);
100 /* Copy generated numbers */
103 for (i__ = 1; i__ <= i__2; ++i__) {
104 x[iv + i__ - 1] = u[i__ - 1];
107 } else if (*idist == 2) {
109 /* Convert generated numbers to uniform (-1,1) distribution */
112 for (i__ = 1; i__ <= i__2; ++i__) {
113 x[iv + i__ - 1] = u[i__ - 1] * 2.f - 1.f;
116 } else if (*idist == 3) {
118 /* Convert generated numbers to normal (0,1) distribution */
121 for (i__ = 1; i__ <= i__2; ++i__) {
122 x[iv + i__ - 1] = sqrt(log(u[(i__ << 1) - 2]) * -2.f) * cos(u[
123 (i__ << 1) - 1] * 6.2831853071795864769252867663f);