SSJ
3.3.1
Stochastic Simulation in Java
|
This class implements methods for generating random variates from the normal distribution \(N(\mu, \sigma)\). More...
Public Member Functions | |
NormalGen (RandomStream s, double mu, double sigma) | |
Creates a normal random variate generator with mean mu and standard deviation sigma , using stream s . | |
NormalGen (RandomStream s) | |
Creates a standard normal random variate generator with mean 0 and standard deviation 1 , using stream s . | |
NormalGen (RandomStream s, NormalDist dist) | |
Creates a random variate generator for the normal distribution dist and stream s . | |
double | getMu () |
Returns the parameter \(\mu\) of this object. | |
double | getSigma () |
Returns the parameter \(\sigma\) of this object. | |
Public Member Functions inherited from RandomVariateGen | |
RandomVariateGen (RandomStream s, Distribution dist) | |
Creates a new random variate generator from the distribution dist , using stream s . More... | |
double | nextDouble () |
Generates a random number from the continuous distribution contained in this object. More... | |
void | nextArrayOfDouble (double[] v, int start, int n) |
Generates n random numbers from the continuous distribution contained in this object. More... | |
double [] | nextArrayOfDouble (int n) |
Generates n random numbers from the continuous distribution contained in this object, and returns them in a new array of size n . More... | |
RandomStream | getStream () |
Returns the umontreal.ssj.rng.RandomStream used by this generator. More... | |
void | setStream (RandomStream stream) |
Sets the umontreal.ssj.rng.RandomStream used by this generator to stream . | |
Distribution | getDistribution () |
Returns the umontreal.ssj.probdist.Distribution used by this generator. More... | |
String | toString () |
Returns a String containing information about the current generator. | |
Static Public Member Functions | |
static double | nextDouble (RandomStream s, double mu, double sigma) |
Generates a variate from the normal distribution with parameters \(\mu= \) mu and \(\sigma= \) sigma , using stream s . | |
Protected Member Functions | |
void | setParams (double mu, double sigma) |
Sets the parameters \(\mu\) and \(\sigma\) of this object. | |
Protected Attributes | |
double | mu |
double | sigma = -1.0 |
Protected Attributes inherited from RandomVariateGen | |
RandomStream | stream |
Distribution | dist |
This class implements methods for generating random variates from the normal distribution \(N(\mu, \sigma)\).
It has mean \(\mu\) and variance \(\sigma^2\), where \(\sigma>0\). Its density function is
\[ f(x) = \frac{1}{\sqrt{2\pi}\sigma} e^{(x-\mu)^2/(2\sigma^2)} \tag{fnormal} \]
The nextDouble
method simply calls inverseF
on the distribution.
The following table gives the CPU time needed to generate \(10^8\) standard normal random variates using the different implementations available in SSJ. The first time is for a generator object (non-static method), and the second time is for the static method where no object is created. These tests were made on a machine with processor AMD Athlon 4000, running Red Hat Linux, with clock speed at 2403 MHz. The static method nextDouble()
for NormalBoxMullerGen
and NormalPolarGen
uses only one number out of two that are generated; thus they are twice slower than the non-static method.
Generator | time in seconds | time in seconds |
(object) | (static) | |
NormalGen | 7.67 | 7.72 |
NormalACRGen | 4.71 | 4.76 |
NormalBoxMullerGen | 16.07 | 31.45 |
NormalPolarGen | 7.31 | 13.74 |
NormalKindermannRamageGen | 5.38 | 5.34 |