last update 20 Sep 2009 |
#include <cvrRandomDistribution.h>
Classes | |
class | parameters |
The parameters for the class randomDistribution. More... | |
class | rndBase |
Pure virtual nested class base of all random number generators. More... | |
class | rndMersenneTwister |
Mersenne Twister Random Number Generator. More... | |
class | rndMinStd |
Linear Congruency Random Number Generator. More... | |
class | rndMinStd0 |
Linear Congruency Random Number Generator. More... | |
class | rndStochastic |
Wrapper for <random> std::tr1::random_device, which is a hardware based true, unpredictable, random number generator. More... | |
class | rndSystem |
Wrapper for the <cstdlib> rand() function. More... | |
Public Types | |
enum | eNumberGenerator { SystemWide, Stochastic, MinStd, MinStd0, MT } |
Public Member Functions | |
randomDistribution () | |
randomDistribution (const parameters &par) | |
randomDistribution (const randomDistribution &other) | |
virtual | ~randomDistribution () |
randomDistribution & | copy (const randomDistribution &other) |
randomDistribution & | operator= (const randomDistribution &other) |
virtual const std::string & | name () const |
virtual randomDistribution * | clone () const |
virtual randomDistribution * | newInstance () const |
const parameters & | getParameters () const |
bool | updateParameters () |
void | setSeed (const uint32 newSeed) |
virtual bool | write (ioHandler &handler, const bool complete=true) const |
virtual bool | read (ioHandler &handler, const bool complete=true) |
Protected Member Functions | |
parameters & | getRWParameters () |
Protected Attributes | |
rndBase * | generator_ |
uint32 | max_ |
The class cvr::randomDistribution is the parent class of all random number generators in the CVR-Lib .
The concept followed in this library is complementary to the standard concept found in the STL <random> classes, which are employed within the classes of the present hierarchy. Since the std::tr1 classes are not implemented by all STL implementations, the CVR-Lib provides the required partial implementations for internal use only.
Note that the standard random number generators and distributions are highly template based, what makes them very efficient for execution time, but relatively hard to be dinamically configured. The present hierarchy is not intended as replacement of the standard concepts. It simply is a wrapper concept that allows the number generators to be configured dinamically, through the accustomed parameter objects, at the cost of reduced speed. In case you need the ultimative speed, then use the standard concept instead, or the original Boost Random Number Library (http://www.boost.org/libs/random/index.html), on which the standard relies. If you need runtime configuration capabilities, then the CVR-Lib concept is for you.
For image applications 32 bit precision is still sufficient. Hence, that is the precision you will get by the number generation of these distributions. This means that internally, the uniformly distributed number generator will produce numbers of type cvr::uint32.
Enumerator with the possible underlying uniformly distributed number generators.
SystemWide | The system-wide random generator makes use of the old C-style rand() function, which is shared among all instances of classes derived from randomDistribution. |
Stochastic |
The stochastic method makes use of the device random generator, which is usually in "/dev/urandom".
It is a non-deterministic random number generator, usually implemented in the operating system, using highly entropic processes. Since it uses file I/O it is realtively slow. |
MinStd |
Linear congruential generator which uses con y .
Therefore, the generated numbers are unsigned of 31 bit precision, and since m and c are relative primes, the repetition period equals m. |
MinStd0 |
Linear congruential generator which uses con y .
Therefore, the generated numbers are unsigned of 31 bit precision, and since m and c are relative primes, the repetition period equals m. |
MT |
Mersenne Twister random number generator.
The code for this generator is based on M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions on Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30. Check also the page http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html |
cvr::randomDistribution::randomDistribution | ( | ) |
Default constructor.
cvr::randomDistribution::randomDistribution | ( | const parameters & | par | ) |
Construct a functor using the given parameters.
cvr::randomDistribution::randomDistribution | ( | const randomDistribution & | other | ) |
virtual cvr::randomDistribution::~randomDistribution | ( | ) | [virtual] |
Destructor.
virtual randomDistribution* cvr::randomDistribution::clone | ( | ) | const [virtual] |
Returns a pointer to a clone of this functor.
Implements cvr::functor.
Reimplemented in cvr::normalDistribution, cvr::uniformContinuousDistribution, cvr::uniformDiscreteDistribution, cvr::univariateContinuousDistribution, and cvr::univariateDiscreteDistribution.
randomDistribution& cvr::randomDistribution::copy | ( | const randomDistribution & | other | ) |
const parameters& cvr::randomDistribution::getParameters | ( | ) | const |
Returns used parameters.
Reimplemented from cvr::parametersManager.
Reimplemented in cvr::normalDistribution, cvr::uniformContinuousDistribution, and cvr::uniformDiscreteDistribution.
parameters& cvr::randomDistribution::getRWParameters | ( | ) | [protected] |
Returns read-writable reference to the internal parameters.
virtual const std::string& cvr::randomDistribution::name | ( | ) | const [virtual] |
Returns the complete name of the functor class.
Implements cvr::functor.
Reimplemented in cvr::normalDistribution, cvr::uniformContinuousDistribution, cvr::uniformDiscreteDistribution, and cvr::univariateContinuousDistribution.
virtual randomDistribution* cvr::randomDistribution::newInstance | ( | ) | const [virtual] |
Returns a pointer to a new instance of this functor.
Implements cvr::functor.
Reimplemented in cvr::normalDistribution, cvr::uniformContinuousDistribution, cvr::uniformDiscreteDistribution, cvr::univariateContinuousDistribution, and cvr::univariateDiscreteDistribution.
randomDistribution& cvr::randomDistribution::operator= | ( | const randomDistribution & | other | ) |
virtual bool cvr::randomDistribution::read | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | [virtual] |
Read the parameters from the given ioHandler.
handler | the ioHandler to be used | |
complete | if true (the default) the enclosing begin/end will be also written, otherwise only the data block will be written. |
Reimplemented from cvr::functor.
void cvr::randomDistribution::setSeed | ( | const uint32 | newSeed | ) |
Shortcut for changing the seed of the number generator.
newSeed | new seed for the number generator. |
bool cvr::randomDistribution::updateParameters | ( | ) | [virtual] |
Update the parameters.
Reimplemented from cvr::parametersManager.
Reimplemented in cvr::normalDistribution, cvr::uniformContinuousDistribution, cvr::uniformDiscreteDistribution, and cvr::univariateContinuousDistribution.
virtual bool cvr::randomDistribution::write | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | const [virtual] |
Write the parameters in the given ioHandler.
handler | the ioHandler to be used | |
complete | if true (the default) the enclosing begin/end will be also written, otherwise only the data block will be written. |
Reimplemented from cvr::functor.
rndBase* cvr::randomDistribution::generator_ [protected] |
Pointer to the random number generator for float.
uint32 cvr::randomDistribution::max_ [protected] |
Maximum number obtainable in the generator.