LAPACK 3.12.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ slarnv()

subroutine slarnv ( integer  idist,
integer, dimension( 4 )  iseed,
integer  n,
real, dimension( * )  x 
)

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

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

Purpose:
 SLARNV 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 REAL 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 SLARUV 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 slarnv.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 REAL X( * )
108* ..
109*
110* =====================================================================
111*
112* .. Parameters ..
113 REAL ONE, TWO
114 parameter( one = 1.0e+0, two = 2.0e+0 )
115 INTEGER LV
116 parameter( lv = 128 )
117 REAL TWOPI
118 parameter( twopi = 6.28318530717958647692528676655900576839e+0 )
119* ..
120* .. Local Scalars ..
121 INTEGER I, IL, IL2, IV
122* ..
123* .. Local Arrays ..
124 REAL U( LV )
125* ..
126* .. Intrinsic Functions ..
127 INTRINSIC cos, log, min, sqrt
128* ..
129* .. External Subroutines ..
130 EXTERNAL slaruv
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 SLARUV to generate IL2 numbers from a uniform (0,1)
143* distribution (IL2 <= LV)
144*
145 CALL slaruv( 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 SLARNV
174*
subroutine slaruv(iseed, n, x)
SLARUV returns a vector of n random real numbers from a uniform distribution.
Definition slaruv.f:95
Here is the call graph for this function:
Here is the caller graph for this function: