1 /* -- translated by f2c (version 19940927).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "f2c.h"
7
slarnd_(integer * idist,integer * iseed)8 doublereal slarnd_(integer *idist, integer *iseed)
9 {
10 /* System generated locals */
11 real ret_val;
12
13 /* Builtin functions */
14 double log(doublereal), sqrt(doublereal), cos(doublereal);
15
16 /* Local variables */
17 static real t1, t2;
18 extern doublereal slaran_(integer *);
19
20
21 /* -- LAPACK auxiliary routine (version 2.0) --
22 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
23 Courant Institute, Argonne National Lab, and Rice University
24 September 30, 1994
25
26
27 Purpose
28 =======
29
30 SLARND returns a random real number from a uniform or normal
31 distribution.
32
33 Arguments
34 =========
35
36 IDIST (input) INTEGER
37 Specifies the distribution of the random numbers:
38 = 1: uniform (0,1)
39 = 2: uniform (-1,1)
40 = 3: normal (0,1)
41
42 ISEED (input/output) INTEGER array, dimension (4)
43 On entry, the seed of the random number generator; the array
44
45 elements must be between 0 and 4095, and ISEED(4) must be
46 odd.
47 On exit, the seed is updated.
48
49 Further Details
50 ===============
51
52 This routine calls the auxiliary routine SLARAN to generate a random
53
54 real number from a uniform (0,1) distribution. The Box-Muller method
55
56 is used to transform numbers from a uniform to a normal distribution.
57
58
59 =====================================================================
60
61
62
63 Generate a real random number from a uniform (0,1) distribution
64
65 Parameter adjustments */
66 --iseed;
67
68 /* Function Body */
69 t1 = slaran_(&iseed[1]);
70
71 if (*idist == 1) {
72
73 /* uniform (0,1) */
74
75 ret_val = t1;
76 } else if (*idist == 2) {
77
78 /* uniform (-1,1) */
79
80 ret_val = t1 * 2.f - 1.f;
81 } else if (*idist == 3) {
82
83 /* normal (0,1) */
84
85 t2 = slaran_(&iseed[1]);
86 ret_val = sqrt(log(t1) * -2.f) * cos(t2 *
87 6.2831853071795864769252867663f);
88 }
89 return ret_val;
90
91 /* End of SLARND */
92
93 } /* slarnd_ */
94
95