#include <BernoulliRng.h>
Public Member Functions | |
BernoulliRng (float successProbability) | |
void | reseed (boost::uint32_t seed) |
Reseed the uniform random number generator that forms the basis of the value stream. | |
bool | nextValue () |
Returns the next value. | |
Private Attributes | |
boost::mt19937 | uniformRng |
uniform random number generator | |
boost::bernoulli_distribution< float > | bernoulliDist |
Bernoulli distribution converter. | |
boost::variate_generator< boost::mt19937 &, boost::bernoulli_distribution< float > > | rng |
Variate generator to produce value with Bernoulli distribution from a uniform RNG. |
That is, a series of values where the value true (1) appears with success probability p and the values false (0) appears with failure probability q = 1 - p. This class simply combines boost::mt19937 (a Meresenne Twister PRNG) with boost::bernoulli_distribution using boost::variate_generator.
Definition at line 41 of file BernoulliRng.h.
BernoulliRng::BernoulliRng | ( | float | successProbability | ) | [explicit] |
Definition at line 28 of file BernoulliRng.cpp.
00029 : bernoulliDist(successProbability), rng(uniformRng, bernoulliDist) 00030 { 00031 }
void BernoulliRng::reseed | ( | boost::uint32_t | seed | ) |
Reseed the uniform random number generator that forms the basis of the value stream.
The RNG will seed itself initially, but it's recommended that you call this method with a better seed. The usual warnings about not calling this method frequently with an input of 'time(0)' apply.
Definition at line 34 of file BernoulliRng.cpp.
References uniformRng.
00035 { 00036 uniformRng.seed(seed); 00037 }
bool BernoulliRng::nextValue | ( | ) |
Returns the next value.
Definition at line 39 of file BernoulliRng.cpp.
References rng.
00040 { 00041 return rng(); 00042 }
boost::mt19937 BernoulliRng::uniformRng [private] |
uniform random number generator
Definition at line 47 of file BernoulliRng.h.
Referenced by reseed().
boost::bernoulli_distribution<float> BernoulliRng::bernoulliDist [private] |
boost::variate_generator< boost::mt19937 &, boost::bernoulli_distribution<float> > BernoulliRng::rng [private] |
Variate generator to produce value with Bernoulli distribution from a uniform RNG.
Definition at line 60 of file BernoulliRng.h.
Referenced by nextValue().