/* * RandomNumberGenerator_Encapsulation.hpp * * Created on: Dec 31, 2010 * Author: heber */ #ifndef RANDOMNUMBERGENERATOR_ENCAPSULATION_HPP_ #define RANDOMNUMBERGENERATOR_ENCAPSULATION_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "CodePatterns/Creator.hpp" #include "RandomNumberGenerator.hpp" #include "RandomNumberGeneratorFactory.hpp" #include "unittests/RandomNumberGeneratorFactoryUnitTest.hpp" /** Template class that encapsulates the random number generators from * random::boost. * * We inherit the interface RandomNumberGenerator such that all are * accessible in the same way (i.e. RandomNumberGeneratorFactory will * spit out only references to RandomNumberGenerator). * * Note that we always returns double values although the distribution * might be integer or even a discrete distribution of integers. * * We need three template parameters: * -# the generator - generates uniform random numbers * -# the distribution - transforms uniform into a desired distribution */ template class RandomNumberGenerator_Encapsulation : public RandomNumberGenerator, public Creator< RandomNumberGenerator, RandomNumberGenerator_Encapsulation > { /** * Factory is friend such that it can access private cstor. */ friend class RandomNumberGeneratorFactory; friend class RandomNumberGeneratorFactoryTest; friend class Creator< RandomNumberGenerator, RandomNumberGenerator_Encapsulation >; public: /** obtain a random number via generator and the specific distribution. * */ double operator()() const { return randomgenerator(); } /** Set the generator's seed. * * @param _seed seed to set to */ void seed(unsigned int _seed) { engine_type.seed(_seed); } /** Getter for the type name of the internal engine. * */ std::string EngineName() { return typeid(engine_type).name(); } /** Getter for the type name of the internal distribution. * */ std::string DistributionName() { return typeid(distribution_type).name(); } /** Constructor that instantiates a specific random number generator and * distribution. * @param _generator_type instance of the desired generator * @param _distribution_type instance of the desired distribution */ RandomNumberGenerator_Encapsulation() : randomgenerator( boost::variate_generator ( engine_type, distribution_type) ) {} /** Destructor of the class. * */ virtual ~RandomNumberGenerator_Encapsulation() {} private: engine engine_type; distribution distribution_type; mutable boost::variate_generator randomgenerator; }; #endif /* RANDOMNUMBERGENERATOR_ENCAPSULATION_HPP_ */