RWTRandGamma<Generator>RWTRand<Generator>
Member Functions | |||
operator()() |
order() |
setOrder() |
#include <rw/rand.h> RWTRandGamma<Generator> gen;
Class RWTRandGamma<Generator> generates random numbers from a gamma distribution:
where a is the order. 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 gamma 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 gamma generator with order = 4 // using the above uniform generator for generator. RWTRandGamma<RWRandGenerator> gamma(uniform, 4);
// Create an exponetial generator with order = 1
// using class RWRandGenerator. RWTRandGamma<RWRandGenerator> gammaOne; // Create a gamma generator with order 31 using a class // MyDoubleRand to generate the uniform [0, 1] deviates. RWTRandGamma<MyDoubleRand> myGamma(31);
// Print a few values. for ( int j = 0; j < 10; j++ ) { cout << "gamma order = 4 = " << gamma(); cout << "\ngamma order = 1 = " << gammaOne(); cout << "\ngamma order = 31 = " << myGamma() << endl; } // Restart one of the generators with another seed value // using the RWRandGenerator method restart(). ( gammaOne.generator() ).restart( 654321L); return 0; }
RWTRandGamma();
Constructs a generator with order = 1.
RWTRandGamma(double ord);
Constructs a generator with order = ord.
RWTRandGamma(const Generator& g, double ord=1);
Constructs a generator with underlying uniform [0, 1] generator g
order = ord.
RWTRandGamma(const RWTRandGamma<Generator>& g);
Constructs self as a copy of g.
double operator()();
Returns the next random number in the sequence.
double order() const;
Returns the value of order for the distribution.
void setOrder(double l);
Sets the value of lamda for the distribution to l.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.