1       REAL             FUNCTION SLARND( IDIST, ISEED )
 2 *
 3 *  -- LAPACK auxiliary routine (version 3.1) --
 4 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
 5 *     November 2006
 6 *
 7 *     .. Scalar Arguments ..
 8       INTEGER            IDIST
 9 *     ..
10 *     .. Array Arguments ..
11       INTEGER            ISEED( 4 )
12 *     ..
13 *
14 *  Purpose
15 *  =======
16 *
17 *  SLARND returns a random real number from a uniform or normal
18 *  distribution.
19 *
20 *  Arguments
21 *  =========
22 *
23 *  IDIST   (input) INTEGER
24 *          Specifies the distribution of the random numbers:
25 *          = 1:  uniform (0,1)
26 *          = 2:  uniform (-1,1)
27 *          = 3:  normal (0,1)
28 *
29 *  ISEED   (input/output) INTEGER array, dimension (4)
30 *          On entry, the seed of the random number generator; the array
31 *          elements must be between 0 and 4095, and ISEED(4) must be
32 *          odd.
33 *          On exit, the seed is updated.
34 *
35 *  Further Details
36 *  ===============
37 *
38 *  This routine calls the auxiliary routine SLARAN to generate a random
39 *  real number from a uniform (0,1) distribution. The Box-Muller method
40 *  is used to transform numbers from a uniform to a normal distribution.
41 *
42 *  =====================================================================
43 *
44 *     .. Parameters ..
45       REAL               ONE, TWO
46       PARAMETER          ( ONE = 1.0E+0, TWO = 2.0E+0 )
47       REAL               TWOPI
48       PARAMETER          ( TWOPI = 6.2831853071795864769252867663E+0 )
49 *     ..
50 *     .. Local Scalars ..
51       REAL               T1, T2
52 *     ..
53 *     .. External Functions ..
54       REAL               SLARAN
55       EXTERNAL           SLARAN
56 *     ..
57 *     .. Intrinsic Functions ..
58       INTRINSIC          COSLOGSQRT
59 *     ..
60 *     .. Executable Statements ..
61 *
62 *     Generate a real random number from a uniform (0,1) distribution
63 *
64       T1 = SLARAN( ISEED )
65 *
66       IF( IDIST.EQ.1 ) THEN
67 *
68 *        uniform (0,1)
69 *
70          SLARND = T1
71       ELSE IF( IDIST.EQ.2 ) THEN
72 *
73 *        uniform (-1,1)
74 *
75          SLARND = TWO*T1 - ONE
76       ELSE IF( IDIST.EQ.3 ) THEN
77 *
78 *        normal (0,1)
79 *
80          T2 = SLARAN( ISEED )
81          SLARND = SQRT-TWO*LOG( T1 ) )*COS( TWOPI*T2 )
82       END IF
83       RETURN
84 *
85 *     End of SLARND
86 *
87       END