SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Used to generate random numbers from an exponential distribution. More...
#include <rw/rand.h>
Public Member Functions | |
RWTRandExponential (double lam=1) | |
RWTRandExponential (const RWTRandExponential< Generator > &g) | |
RWTRandExponential (const Generator &g, double lam=1) | |
virtual double | operator() () |
virtual size_t | operator() (double *out, size_t n) |
double | lowBound () const |
double | highBound () const |
double | lambda () const |
void | setLambda (double l) |
Class RWTRandExponential<Generator> generates random numbers from an exponential distribution:
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 exponentially distributed random numbers may be changed by varying the Generator template parameter 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> RWTRandExponential<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 an exponential generator with lambda = 4.5 // using the above uniform generator. RWTRandExponential<RWRandGenerator> exp(uniform, 4.5); // Create an exponetial generator with lambda = 1 using class // RWRandGenerator. RWTRandExponential<RWRandGenerator> expOne; // Create an exponential generator with lambda 3.14 using // a class MyDoubleRand to generate the uniform [0, 1] deviates. RWTRandExponential<MyDoubleRand> myExp(3.14); // Print a few values. for ( int j = 0; j < 10; j++ ) { cout << "exponential lambda = 4.5 = " << exp(); cout << "\nexponential lambda = 1 = " << expOne(); cout << "\nexponential lambda = 3.14 = " << myExp() << endl; } // Restart one of the generators with another seed value // using the RWRandGenerator method restart(). ( expOne.generator() ).restart( 654321L); return 0; }
RWTRandExponential< Generator >::RWTRandExponential | ( | double | lam = 1 |
) |
Constructs a generator with lambda = lam.
RWTRandExponential< Generator >::RWTRandExponential | ( | const RWTRandExponential< Generator > & | g | ) |
Constructs self as a copy of g.
RWTRandExponential< Generator >::RWTRandExponential | ( | const Generator & | g, | |
double | lam = 1 | |||
) |
Constructs a generator with underlying uniform [0, 1] generator g lambda=lam.
double RWTRandExponential< Generator >::highBound | ( | ) | const |
Returns the upper bound of 99% of the distribution.
double RWTRandExponential< Generator >::lambda | ( | ) | const [inline] |
Returns the value of lambda for the distribution.
double RWTRandExponential< Generator >::lowBound | ( | ) | const |
Returns the lower bound of 99% of the distribution.
virtual size_t RWTRandExponential< 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 RWTRandExponential< Generator >::operator() | ( | ) | [virtual] |
Returns the next random number in the sequence.
Implements RWRandInterface.
void RWTRandExponential< Generator >::setLambda | ( | double | l | ) | [inline] |
Sets the value of lambda
for the distribution to l.
© 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.