rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWTRandPoisson< Generator > Class Template Reference
[Statistics]

Used to generate random numbers from a Poisson distribution. More...

#include <rw/rand.h>

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

List of all members.

Public Member Functions

 RWTRandPoisson (double m=1)
 RWTRandPoisson (const RWTRandPoisson< Generator > &g)
 RWTRandPoisson (const Generator &g, double m=1)
virtual double operator() ()
virtual size_t operator() (double *out, size_t n)
double mean () const
void setMean (double m)

Detailed Description

template<class Generator>
class RWTRandPoisson< Generator >

Class RWTRandPoisson<Generator> generates random numbers from a Poisson distribution:

\[ f(x) = \left\{\begin{matrix} \frac{\mu^xe^{- \mu}}{x!} & \text{x = 0, 1, 2, ...} \\ \text{0} & \text{otherwise} \end{matrix}\right. \]

where $ \mu$ 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.

Synopsis

 #include <rw/rand.h>
 RWTRandPoisson<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 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;
 }

Constructor & Destructor Documentation

template<class Generator>
RWTRandPoisson< Generator >::RWTRandPoisson ( double  m = 1  ) 

Constructs a generator with mean = m.

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

Constructs self as a copy of g.

template<class Generator>
RWTRandPoisson< Generator >::RWTRandPoisson ( const Generator &  g,
double  m = 1 
)

Constructs a generator with underlying uniform [0, 1] generator g and mean m.


Member Function Documentation

template<class Generator>
double RWTRandPoisson< Generator >::mean (  )  const [inline]

Returns the value of mean for the distribution.

template<class Generator>
virtual size_t RWTRandPoisson< 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 RWTRandPoisson< Generator >::operator() (  )  [virtual]

Returns the next random number in the sequence.

Implements RWRandInterface.

template<class Generator>
void RWTRandPoisson< Generator >::setMean ( double  m  ) 

Sets the value of the mean of the distribution to m.

 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.