LAPACK  3.6.1
LAPACK: Linear Algebra PACKage
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.
Date
September 2012
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 99 of file dlarnv.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  DOUBLE PRECISION x( * )
111 * ..
112 *
113 * =====================================================================
114 *
115 * .. Parameters ..
116  DOUBLE PRECISION one, two
117  parameter ( one = 1.0d+0, two = 2.0d+0 )
118  INTEGER lv
119  parameter ( lv = 128 )
120  DOUBLE PRECISION twopi
121  parameter ( twopi = 6.2831853071795864769252867663d+0 )
122 * ..
123 * .. Local Scalars ..
124  INTEGER i, il, il2, iv
125 * ..
126 * .. Local Arrays ..
127  DOUBLE PRECISION u( lv )
128 * ..
129 * .. Intrinsic Functions ..
130  INTRINSIC cos, log, min, sqrt
131 * ..
132 * .. External Subroutines ..
133  EXTERNAL dlaruv
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 DLARUV to generate IL2 numbers from a uniform (0,1)
146 * distribution (IL2 <= LV)
147 *
148  CALL dlaruv( 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 DLARNV
177 *
subroutine dlaruv(ISEED, N, X)
DLARUV returns a vector of n random real numbers from a uniform distribution.
Definition: dlaruv.f:97

Here is the call graph for this function:

Here is the caller graph for this function: