 LAPACK 3.11.0 LAPACK: Linear Algebra PACKage
Searching...
No Matches

## ◆ dlarnv()

 subroutine dlarnv ( integer IDIST, integer, dimension( 4 ) ISEED, integer N, double precision, dimension( * ) X )

DLARNV returns a vector of random numbers from a uniform or normal distribution.

Purpose:
``` DLARNV returns a vector of n random real numbers from a uniform or
normal distribution.```
Parameters
 [in] IDIST ``` IDIST is INTEGER Specifies the distribution of the random numbers: = 1: uniform (0,1) = 2: uniform (-1,1) = 3: normal (0,1)``` [in,out] ISEED ``` ISEED is INTEGER array, dimension (4) On entry, the seed of the random number generator; the array elements must be between 0 and 4095, and ISEED(4) must be odd. On exit, the seed is updated.``` [in] N ``` N is INTEGER The number of random numbers to be generated.``` [out] X ``` X is DOUBLE PRECISION array, dimension (N) The generated random numbers.```
Further Details:
```  This routine calls the auxiliary routine DLARUV to generate random
real numbers from a uniform (0,1) distribution, in batches of up to
128 using vectorisable code. The Box-Muller method is used to
transform numbers from a uniform to a normal distribution.```

Definition at line 96 of file dlarnv.f.

97*
98* -- LAPACK auxiliary routine --
99* -- LAPACK is a software package provided by Univ. of Tennessee, --
100* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
101*
102* .. Scalar Arguments ..
103 INTEGER IDIST, N
104* ..
105* .. Array Arguments ..
106 INTEGER ISEED( 4 )
107 DOUBLE PRECISION X( * )
108* ..
109*
110* =====================================================================
111*
112* .. Parameters ..
113 DOUBLE PRECISION ONE, TWO
114 parameter( one = 1.0d+0, two = 2.0d+0 )
115 INTEGER LV
116 parameter( lv = 128 )
117 DOUBLE PRECISION TWOPI
118 parameter( twopi = 6.28318530717958647692528676655900576839d+0 )
119* ..
120* .. Local Scalars ..
121 INTEGER I, IL, IL2, IV
122* ..
123* .. Local Arrays ..
124 DOUBLE PRECISION U( LV )
125* ..
126* .. Intrinsic Functions ..
127 INTRINSIC cos, log, min, sqrt
128* ..
129* .. External Subroutines ..
130 EXTERNAL dlaruv
131* ..
132* .. Executable Statements ..
133*
134 DO 40 iv = 1, n, lv / 2
135 il = min( lv / 2, n-iv+1 )
136 IF( idist.EQ.3 ) THEN
137 il2 = 2*il
138 ELSE
139 il2 = il
140 END IF
141*
142* Call DLARUV to generate IL2 numbers from a uniform (0,1)
143* distribution (IL2 <= LV)
144*
145 CALL dlaruv( iseed, il2, u )
146*
147 IF( idist.EQ.1 ) THEN
148*
149* Copy generated numbers
150*
151 DO 10 i = 1, il
152 x( iv+i-1 ) = u( i )
153 10 CONTINUE
154 ELSE IF( idist.EQ.2 ) THEN
155*
156* Convert generated numbers to uniform (-1,1) distribution
157*
158 DO 20 i = 1, il
159 x( iv+i-1 ) = two*u( i ) - one
160 20 CONTINUE
161 ELSE IF( idist.EQ.3 ) THEN
162*
163* Convert generated numbers to normal (0,1) distribution
164*
165 DO 30 i = 1, il
166 x( iv+i-1 ) = sqrt( -two*log( u( 2*i-1 ) ) )*
167 \$ cos( twopi*u( 2*i ) )
168 30 CONTINUE
169 END IF
170 40 CONTINUE
171 RETURN
172*
173* End of DLARNV
174*
subroutine dlaruv(ISEED, N, X)
DLARUV returns a vector of n random real numbers from a uniform distribution.
Definition: dlaruv.f:95
Here is the call graph for this function:
Here is the caller graph for this function: