SourcePro® 2024.1 |
SourcePro® API Reference Guide |
Used to generate random numbers from a normal distribution. More...
#include <rw/rand.h>
Public Member Functions | |
RWTRandNormal () | |
RWTRandNormal (const Generator &g, double mean=0, double variance=1) | |
RWTRandNormal (const RWTRandNormal< Generator > &g) | |
RWTRandNormal (double mean, double variance) | |
double | mean () const |
virtual double | operator() () |
virtual size_t | operator() (double *out, size_t n) |
void | setMean (double m) |
void | setVariance (double v) |
double | variance () const |
Public Member Functions inherited from RWTRand< Generator > | |
RWTRand () | |
RWTRand (const Generator &g) | |
RWTRand (const RWTRand< Generator > &x) | |
Generator & | generator () |
const Generator & | generator () const |
void | setGenerator (const Generator &x) |
void | setGenerator (const RWTRand< Generator > &x) |
Class RWTRandNormal generates random numbers from a normal distribution:
\[ f(x) = \frac{1}{\sigma \sqrt{2 \pi}}\text{exp} \begin{bmatrix} -\frac{(x - \mu )^2)}{2 \sigma ^2} \end{bmatrix} , - \infty < \text{x} < \infty \]
where \( \mu\) is the mean, and \( \sigma ^2\) is the variance. The algorithm used to generate the random numbers begins with random numbers generated from a uniform distribution on the interval [0, 1]. Thus, the speed and statistical properties of the normal random numbers may be varied by varying the Generator template parameter, which is responsible for generating these uniformly distributed numbers.
The class Generator must be a function object whose function call operator returns a uniform random double between 0 and 1. The class RWRandGenerator supplied with the library may be used.
RWTRandNormal< Generator >::RWTRandNormal | ( | ) |
Constructs a generator with mean 0 and variance 1.
RWTRandNormal< Generator >::RWTRandNormal | ( | double | mean, |
double | variance ) |
Constructs a generator with the mean specified by the first parameter and variance specified by the second parameter.
RWTRandNormal< Generator >::RWTRandNormal | ( | const RWTRandNormal< Generator > & | g | ) |
Constructs self as a copy of g.
RWTRandNormal< Generator >::RWTRandNormal | ( | const Generator & | g, |
double | mean = 0, | ||
double | variance = 1 ) |
Constructs a generator with underlying uniform [0, 1] generator g and the specified mean and variance.
|
inline |
Returns the mean of the distribution.
|
virtual |
Returns the next random number in the sequence.
Implements RWRandInterface.
|
virtual |
Assigns random numbers to n elements in out. Returns the number of random numbers generated.
Implements RWRandInterface.
|
inline |
Sets the mean of the distribution to m.
void RWTRandNormal< Generator >::setVariance | ( | double | v | ) |
Sets the variance of the distribution to v.
|
inline |
Returns the variance of the distribution.
Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |