SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
RWTRandGamma< Generator > Class Template Reference

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

#include <rw/rand.h>

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

Public Member Functions

 RWTRandGamma (const Generator &g, int ord=1)
 
 RWTRandGamma (const RWTRandGamma< Generator > &g)
 
 RWTRandGamma (int ord=1)
 
virtual double operator() ()
 
virtual size_t operator() (double *out, size_t n)
 
int order () const
 
void setOrder (int order)
 
- Public Member Functions inherited from RWTRand< Generator >
 RWTRand ()
 
 RWTRand (const Generator &g)
 
 RWTRand (const RWTRand< Generator > &x)
 
Generator & generator ()
 
const Generator & generator () const
 
void setGenerator (const Generator &x)
 
void setGenerator (const RWTRand< Generator > &x)
 

Detailed Description

template<class Generator>
class RWTRandGamma< Generator >

Class RWTRandGamma generates random numbers from a gamma distribution:

\[ f(x) = \frac{x^{a-1}e^{-x}}{\Gamma (a)}, x > 0 \]

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.

Synopsis
#include <rw/rand.h>
Used to generate random numbers from a gamma distribution.
Definition rand.h:608
Example
#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 exponential generator with order = 1
// using class RWRandGenerator.
// Create a gamma generator with order 31 using a class
// MyDoubleRand to generate the uniform [0, 1] deviates.
// 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;
}
Generates random numbers uniformly distributed over the interval [0, 1].
Definition randgen.h:61
const Generator & generator() const
Definition rand.h:131

Constructor & Destructor Documentation

◆ RWTRandGamma() [1/3]

template<class Generator >
RWTRandGamma< Generator >::RWTRandGamma ( int ord = 1)

Constructs a generator with order = ord.

◆ RWTRandGamma() [2/3]

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

Constructs self as a copy of g.

◆ RWTRandGamma() [3/3]

template<class Generator >
RWTRandGamma< Generator >::RWTRandGamma ( const Generator & g,
int ord = 1 )

Constructs a generator with underlying uniform [0, 1] generator g order = ord.

Member Function Documentation

◆ operator()() [1/2]

template<class Generator >
virtual double RWTRandGamma< Generator >::operator() ( )
virtual

Returns the next random number in the sequence.

Implements RWRandInterface.

◆ operator()() [2/2]

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

◆ order()

template<class Generator >
int RWTRandGamma< Generator >::order ( ) const
inline

Returns the value of order for the distribution.

◆ setOrder()

template<class Generator >
void RWTRandGamma< Generator >::setOrder ( int order)
inline

Sets the value of lambda for the distribution to l.

Copyright © 2024 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.