LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
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.
Date
September 2012
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 99 of file slarnv.f.

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

Here is the call graph for this function:

Here is the caller graph for this function: