LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages

◆ 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.

Download DLARNV + dependencies [TGZ] [ZIP] [TXT]

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. !>
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
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 94 of file dlarnv.f.

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