|
kusano |
7d535a |
/* -- translated by f2c (version 19940927).
|
|
kusano |
7d535a |
You must link the resulting object file with the libraries:
|
|
kusano |
7d535a |
-lf2c -lm (in that order)
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include "f2c.h"
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
doublereal slarnd_(integer *idist, integer *iseed)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
/* System generated locals */
|
|
kusano |
7d535a |
real ret_val;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Builtin functions */
|
|
kusano |
7d535a |
double log(doublereal), sqrt(doublereal), cos(doublereal);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Local variables */
|
|
kusano |
7d535a |
static real t1, t2;
|
|
kusano |
7d535a |
extern doublereal slaran_(integer *);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* -- LAPACK auxiliary routine (version 2.0) --
|
|
kusano |
7d535a |
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
|
|
kusano |
7d535a |
Courant Institute, Argonne National Lab, and Rice University
|
|
kusano |
7d535a |
September 30, 1994
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Purpose
|
|
kusano |
7d535a |
=======
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
SLARND returns a random real number from a uniform or normal
|
|
kusano |
7d535a |
distribution.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Arguments
|
|
kusano |
7d535a |
=========
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
IDIST (input) INTEGER
|
|
kusano |
7d535a |
Specifies the distribution of the random numbers:
|
|
kusano |
7d535a |
= 1: uniform (0,1)
|
|
kusano |
7d535a |
= 2: uniform (-1,1)
|
|
kusano |
7d535a |
= 3: normal (0,1)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
ISEED (input/output) INTEGER array, dimension (4)
|
|
kusano |
7d535a |
On entry, the seed of the random number generator; the array
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
elements must be between 0 and 4095, and ISEED(4) must be
|
|
kusano |
7d535a |
odd.
|
|
kusano |
7d535a |
On exit, the seed is updated.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Further Details
|
|
kusano |
7d535a |
===============
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
This routine calls the auxiliary routine SLARAN to generate a random
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
real number from a uniform (0,1) distribution. The Box-Muller method
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
is used to transform numbers from a uniform to a normal distribution.
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
=====================================================================
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Generate a real random number from a uniform (0,1) distribution
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
Parameter adjustments */
|
|
kusano |
7d535a |
--iseed;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* Function Body */
|
|
kusano |
7d535a |
t1 = slaran_(&iseed[1]);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if (*idist == 1) {
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* uniform (0,1) */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
ret_val = t1;
|
|
kusano |
7d535a |
} else if (*idist == 2) {
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* uniform (-1,1) */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
ret_val = t1 * 2.f - 1.f;
|
|
kusano |
7d535a |
} else if (*idist == 3) {
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* normal (0,1) */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
t2 = slaran_(&iseed[1]);
|
|
kusano |
7d535a |
ret_val = sqrt(log(t1) * -2.f) * cos(t2 *
|
|
kusano |
7d535a |
6.2831853071795864769252867663f);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
return ret_val;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* End of SLARND */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
} /* slarnd_ */
|
|
kusano |
7d535a |
|