RWTRandExponential<Generator>RWTRand<Generator>
Member Functions | ||
highBound() lamda() |
lowBound() operator()() |
setLambda() |
#include <rw/rand.h> RWTRandExponential<Generator> gen;
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> #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(double lam=1);
Constructs a generator with lambda = lam.
RWTRandExponential(const Generator& g, double lam=1);
Constructs a generator with underlying uniform [0, 1] generator g lambda=lam.
RWTRandExponential(const RWTRandExponential<Generator>& g);
Constructs self as a copy of g.
double operator()()
Returns the next random number in the sequence.
double highBound() const;
Returns the upper bound of 99% of the distribution.
lamda() const;
Returns the value of lambda for the distribution.
double lowBound() const;
Returns the lower bound of 99% of the distribution.
void setLambda(double l);
Sets the value of lambda for the distribution to l.
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.