```001:       SUBROUTINE DLARNV( IDIST, ISEED, N, X )
002: *
003: *  -- LAPACK auxiliary routine (version 3.2) --
004: *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
005: *     November 2006
006: *
007: *     .. Scalar Arguments ..
008:       INTEGER            IDIST, N
009: *     ..
010: *     .. Array Arguments ..
011:       INTEGER            ISEED( 4 )
012:       DOUBLE PRECISION   X( * )
013: *     ..
014: *
015: *  Purpose
016: *  =======
017: *
018: *  DLARNV returns a vector of n random real numbers from a uniform or
019: *  normal distribution.
020: *
021: *  Arguments
022: *  =========
023: *
024: *  IDIST   (input) INTEGER
025: *          Specifies the distribution of the random numbers:
026: *          = 1:  uniform (0,1)
027: *          = 2:  uniform (-1,1)
028: *          = 3:  normal (0,1)
029: *
030: *  ISEED   (input/output) INTEGER array, dimension (4)
031: *          On entry, the seed of the random number generator; the array
032: *          elements must be between 0 and 4095, and ISEED(4) must be
033: *          odd.
034: *          On exit, the seed is updated.
035: *
036: *  N       (input) INTEGER
037: *          The number of random numbers to be generated.
038: *
039: *  X       (output) DOUBLE PRECISION array, dimension (N)
040: *          The generated random numbers.
041: *
042: *  Further Details
043: *  ===============
044: *
045: *  This routine calls the auxiliary routine DLARUV to generate random
046: *  real numbers from a uniform (0,1) distribution, in batches of up to
047: *  128 using vectorisable code. The Box-Muller method is used to
048: *  transform numbers from a uniform to a normal distribution.
049: *
050: *  =====================================================================
051: *
052: *     .. Parameters ..
053:       DOUBLE PRECISION   ONE, TWO
054:       PARAMETER          ( ONE = 1.0D+0, TWO = 2.0D+0 )
055:       INTEGER            LV
056:       PARAMETER          ( LV = 128 )
057:       DOUBLE PRECISION   TWOPI
058:       PARAMETER          ( TWOPI = 6.2831853071795864769252867663D+0 )
059: *     ..
060: *     .. Local Scalars ..
061:       INTEGER            I, IL, IL2, IV
062: *     ..
063: *     .. Local Arrays ..
064:       DOUBLE PRECISION   U( LV )
065: *     ..
066: *     .. Intrinsic Functions ..
067:       INTRINSIC          COS, LOG, MIN, SQRT
068: *     ..
069: *     .. External Subroutines ..
070:       EXTERNAL           DLARUV
071: *     ..
072: *     .. Executable Statements ..
073: *
074:       DO 40 IV = 1, N, LV / 2
075:          IL = MIN( LV / 2, N-IV+1 )
076:          IF( IDIST.EQ.3 ) THEN
077:             IL2 = 2*IL
078:          ELSE
079:             IL2 = IL
080:          END IF
081: *
082: *        Call DLARUV to generate IL2 numbers from a uniform (0,1)
083: *        distribution (IL2 <= LV)
084: *
085:          CALL DLARUV( ISEED, IL2, U )
086: *
087:          IF( IDIST.EQ.1 ) THEN
088: *
089: *           Copy generated numbers
090: *
091:             DO 10 I = 1, IL
092:                X( IV+I-1 ) = U( I )
093:    10       CONTINUE
094:          ELSE IF( IDIST.EQ.2 ) THEN
095: *
096: *           Convert generated numbers to uniform (-1,1) distribution
097: *
098:             DO 20 I = 1, IL
099:                X( IV+I-1 ) = TWO*U( I ) - ONE
100:    20       CONTINUE
101:          ELSE IF( IDIST.EQ.3 ) THEN
102: *
103: *           Convert generated numbers to normal (0,1) distribution
104: *
105:             DO 30 I = 1, IL
106:                X( IV+I-1 ) = SQRT( -TWO*LOG( U( 2*I-1 ) ) )*
107:      \$                       COS( TWOPI*U( 2*I ) )
108:    30       CONTINUE
109:          END IF
110:    40 CONTINUE
111:       RETURN
112: *
113: *     End of DLARNV
114: *
115:       END
116: ```