SCALAPACK 2.2.2
LAPACK: Linear Algebra PACKage
All Classes Files Functions Variables Typedefs Macros
slarnd.f
Go to the documentation of this file.
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 cos, log, sqrt
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 ELSE
83 slarnd = one
84 END IF
85 RETURN
86*
87* End of SLARND
88*
89 END
real function slaran(iseed)
Definition slaran.f:2
real function slarnd(idist, iseed)
Definition slarnd.f:2