src/biu/RandomNumberFactory.cc
Go to the documentation of this file.00001 00002 #include "biu/RandomNumberFactory.hh" 00003 #include <biu/assertbiu.hh> 00004 00005 namespace biu 00006 { 00007 00008 // default random number generator 00009 RandomNumberGenerator* RandomNumberFactory::rng = new RNG_ISO(); 00010 00011 // pointer object to random generator function for RNF usage with STL 00012 // algorithms like stl::random_shuffle 00013 unsigned int (*RandomNumberFactory::pt_getRN)(unsigned int) = &RandomNumberFactory::getRN; 00014 00015 00016 RandomNumberFactory::RandomNumberFactory() 00017 { 00018 } 00019 00020 RandomNumberFactory::~RandomNumberFactory() 00021 { 00022 } 00023 00024 RandomNumberGenerator& 00025 RandomNumberFactory::getRNG() { 00026 return *rng; 00027 } 00028 00029 void 00030 RandomNumberFactory::setRNG(RandomNumberGenerator& rng_) { 00031 00032 delete rng; // delete old RNG 00033 00034 rng = rng_.copy(); // set new one 00035 } 00036 00037 void 00038 RandomNumberFactory::setRNG(RandomNumberGenerator* rng_) { 00039 00040 assertbiu( rng_ != NULL, "given RNG is not available (NULL)"); 00041 delete rng; // delete old RNG 00042 00043 rng = rng_->copy(); // set new one 00044 } 00045 00046 unsigned int 00047 RandomNumberFactory::getRN(void) { 00048 return rng->getRN(); 00049 } 00050 00051 unsigned int 00052 RandomNumberFactory::getRN(unsigned int max) { 00053 assertbiu(max != 0, "maximal value == 0 would cause division by zero"); 00054 return rng->getRN()%max; 00055 } 00056 00057 unsigned int 00058 RandomNumberFactory::getMaxRN(void) { 00059 return rng->getMaxRN(); 00060 } 00061 00062 } // namespace