SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Used to generate random numbers from a normal distribution. More...
#include <rw/rand.h>
Public Member Functions | |
RWTRandNormal () | |
RWTRandNormal (double mean, double variance) | |
RWTRandNormal (const RWTRandNormal< Generator > &g) | |
RWTRandNormal (const Generator &g, double mean=0, double variance=1) | |
virtual double | operator() () |
virtual size_t | operator() (double *out, size_t n) |
void | setMean (double m) |
void | setVariance (double v) |
double | mean () const |
double | variance () const |
Class RWTRandNormal<Generator> generates random numbers from a normal distribution:
where is the mean, and 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.
#include <rw/rand.h> RWTRandNormal<Generator> gen;
#include <rw/rand.h> #include <iostream.h> #include "myrand.h" int main() { // Create a uniform generator on [0, 1] with an // initial seed value. RWRandGenerator uniform(123456L); // Create a normal generator with mean 75 and variance 100 // using the above uniform generator for generator. RWTRandNormal<RWRandGenerator> normal(uniform, 75.0, 100.0); // Create a normal generator with mean 0 and variance 1 // using class RWRandGenerator. RWTRandNormal<RWRandGenerator> normalZeroOne; // Create a normal generator with mean -3.14 and variance // 345.67 using a class MyDoubleRand to generate the // uniform [0, 1] deviates. RWTRandNormal<MyDoubleRand> myRandNormal( -3.14, 345.67 ); // Print a few values. for ( int j = 0; j < 10; j++ ) { cout << "normal(75,100) = " << normal(); cout << "\normal(0,1) = " << normalZeroOne(); cout << "normal(-3.14,345.67) = " << myRandNormal() << endl; } // Restart one of the generators with another seed value // using the RWRandGenerator method restart(). ( normalZeroOne.generator() ).restart( 654321L); return 0; }
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.
double RWTRandNormal< Generator >::mean | ( | ) | const [inline] |
Returns the mean of the distribution.
virtual size_t RWTRandNormal< Generator >::operator() | ( | double * | out, | |
size_t | n | |||
) | [virtual] |
Assigns random numbers to n elements in out. Returns the number of random numbers generated.
Implements RWRandInterface.
virtual double RWTRandNormal< Generator >::operator() | ( | ) | [virtual] |
Returns the next random number in the sequence.
Implements RWRandInterface.
void RWTRandNormal< Generator >::setMean | ( | double | m | ) | [inline] |
Sets the mean of the distribution to m.
void RWTRandNormal< Generator >::setVariance | ( | double | v | ) |
Sets the variance of the distribution to v.
double RWTRandNormal< Generator >::variance | ( | ) | const [inline] |
Returns the variance of the distribution.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.