LAPACK 3.3.0
|
00001 REAL FUNCTION SLARND( IDIST, ISEED ) 00002 * 00003 * -- LAPACK auxiliary routine (version 3.1) -- 00004 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. 00005 * November 2006 00006 * 00007 * .. Scalar Arguments .. 00008 INTEGER IDIST 00009 * .. 00010 * .. Array Arguments .. 00011 INTEGER ISEED( 4 ) 00012 * .. 00013 * 00014 * Purpose 00015 * ======= 00016 * 00017 * SLARND returns a random real number from a uniform or normal 00018 * distribution. 00019 * 00020 * Arguments 00021 * ========= 00022 * 00023 * IDIST (input) INTEGER 00024 * Specifies the distribution of the random numbers: 00025 * = 1: uniform (0,1) 00026 * = 2: uniform (-1,1) 00027 * = 3: normal (0,1) 00028 * 00029 * ISEED (input/output) INTEGER array, dimension (4) 00030 * On entry, the seed of the random number generator; the array 00031 * elements must be between 0 and 4095, and ISEED(4) must be 00032 * odd. 00033 * On exit, the seed is updated. 00034 * 00035 * Further Details 00036 * =============== 00037 * 00038 * This routine calls the auxiliary routine SLARAN to generate a random 00039 * real number from a uniform (0,1) distribution. The Box-Muller method 00040 * is used to transform numbers from a uniform to a normal distribution. 00041 * 00042 * ===================================================================== 00043 * 00044 * .. Parameters .. 00045 REAL ONE, TWO 00046 PARAMETER ( ONE = 1.0E+0, TWO = 2.0E+0 ) 00047 REAL TWOPI 00048 PARAMETER ( TWOPI = 6.2831853071795864769252867663E+0 ) 00049 * .. 00050 * .. Local Scalars .. 00051 REAL T1, T2 00052 * .. 00053 * .. External Functions .. 00054 REAL SLARAN 00055 EXTERNAL SLARAN 00056 * .. 00057 * .. Intrinsic Functions .. 00058 INTRINSIC COS, LOG, SQRT 00059 * .. 00060 * .. Executable Statements .. 00061 * 00062 * Generate a real random number from a uniform (0,1) distribution 00063 * 00064 T1 = SLARAN( ISEED ) 00065 * 00066 IF( IDIST.EQ.1 ) THEN 00067 * 00068 * uniform (0,1) 00069 * 00070 SLARND = T1 00071 ELSE IF( IDIST.EQ.2 ) THEN 00072 * 00073 * uniform (-1,1) 00074 * 00075 SLARND = TWO*T1 - ONE 00076 ELSE IF( IDIST.EQ.3 ) THEN 00077 * 00078 * normal (0,1) 00079 * 00080 T2 = SLARAN( ISEED ) 00081 SLARND = SQRT( -TWO*LOG( T1 ) )*COS( TWOPI*T2 ) 00082 END IF 00083 RETURN 00084 * 00085 * End of SLARND 00086 * 00087 END