RWTRandPoisson<Generator>RWTRand<Generator>
Member Functions | |||
mean() |
operator()() |
setMean() |
#include <rw/rand.h> RWTRandPoisson<Generator> gen;
Class RWTRandPoisson<Generator> generates random numbers from a Poisson distribution:
where µ is the mean. 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 Poisson random number generator may be varied by varying the Generator template parameter, which is responsible for generating the 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> #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 Poisson generator with mean = 4 // using the above uniform generator for generator. RWTRandPoisson<RWRandGenerator> poisson(uniform, 4); // Create a Poisson generator with mean = 1 using class // RWRandGenerator. RWTRandPoisson<RWRandGenerator> poissonOne; // Create a poisson generator with mean 31 using a class // MyDoubleRand to generate the uniform [0, 1] deviates. RWTRandPoisson<MyDoubleRand> myPoisson(31); // Print a few values for ( int j = 0; j < 10; j++ ) { cout << "poisson mean = 4 = " << gamma(); cout << "\npoisson mean = 1 = " << gammaOne(); cout << "\npoisson mean = 31 = " << myGamma() << endl; } // Restart one of the generators with another seed value // using the RWRandGenerator method restart(). ( poissonOne.generator() ).restart( 654321L); return 0; }
RWTRandPoisson();
Constructs a generator with mean = 1.
RWTRandPoisson(double m=1);
Constructs a generator with mean = m.
RWTRandPoisson(const Generator& g, double m=1);
Constructs a generator with underlying uniform [0, 1] generator g and mean m.
RWTRandPoisson(const RWTRandPoisson<Generator>& g);
Constructs self as a copy of g.
double operator()();
Returns the next random number in the sequence.
double mean() const;
Returns the value of mean for the distribution.
void setMean(double m);
Sets the value of the mean of the distribution to m.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.