rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWTRandExponential< Generator > Class Template Reference
[Statistics]

Used to generate random numbers from an exponential distribution. More...

#include <rw/rand.h>

Inheritance diagram for RWTRandExponential< Generator >:
RWTRand< Generator > RWRandInterface

List of all members.

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)

Detailed Description

template<class Generator>
class RWTRandExponential< Generator >

Class RWTRandExponential<Generator> generates random numbers from an exponential distribution:

\[ g(w) = \left\{\begin{matrix} \lambda e^{-\lambda \omega } , & 0 < w \\ 0 \hfill, & w \leq 0 \end{matrix}\right. \]

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.

Synopsis

 #include <rw/rand.h>
 RWTRandExponential<Generator> gen;

Examples

 #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;
 }

Constructor & Destructor Documentation

template<class Generator>
RWTRandExponential< Generator >::RWTRandExponential ( double  lam = 1  ) 

Constructs a generator with lambda = lam.

template<class Generator>
RWTRandExponential< Generator >::RWTRandExponential ( const RWTRandExponential< Generator > &  g  ) 

Constructs self as a copy of g.

template<class Generator>
RWTRandExponential< Generator >::RWTRandExponential ( const Generator &  g,
double  lam = 1 
)

Constructs a generator with underlying uniform [0, 1] generator g lambda=lam.


Member Function Documentation

template<class Generator>
double RWTRandExponential< Generator >::highBound (  )  const

Returns the upper bound of 99% of the distribution.

template<class Generator>
double RWTRandExponential< Generator >::lambda (  )  const [inline]

Returns the value of lambda for the distribution.

template<class Generator>
double RWTRandExponential< Generator >::lowBound (  )  const

Returns the lower bound of 99% of the distribution.

template<class Generator>
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.

template<class Generator>
virtual double RWTRandExponential< Generator >::operator() (  )  [virtual]

Returns the next random number in the sequence.

Implements RWRandInterface.

template<class Generator>
void RWTRandExponential< Generator >::setLambda ( double  l  )  [inline]

Sets the value of lambda for the distribution to l.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© 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.