BWAPI
SnippyHolloW-BroodwarBotQ-f01ab56/src/Utils/RandomGenerators.h
Go to the documentation of this file.
00001 #pragma once
00002 #include "Utils/CSingleton.h"
00003 #include <ctime>
00004 #include <boost/random/linear_congruential.hpp>
00005 #include <boost/random/uniform_real.hpp>
00006 #include <boost/random/uniform_int.hpp>
00007 #include <boost/random/variate_generator.hpp>
00008 
00009 typedef boost::minstd_rand base_generator_type; 
00010 // can try also boost::mt19937 or boost::ecuyer1988
00011 typedef boost::variate_generator<base_generator_type&, boost::uniform_real<> >
00012         uniform_generator;
00013 
00014 template <int _left, int _right>
00015 class RandomGenerators : public CSingleton<RandomGenerators<_left, _right> >
00016 {
00017         friend class CSingleton<RandomGenerators<_left, _right> >;
00018 private:
00019     base_generator_type generator;
00020         uniform_generator uni_real_generator;
00021     RandomGenerators()
00022                 : generator(base_generator_type(static_cast<unsigned int>(std::time(0))))
00023                 , uni_real_generator(uniform_generator(generator, boost::uniform_real<>
00024                 (_left, _right)))
00025         { }
00026         ~RandomGenerators() { }
00027 public:
00028         double uni() { return uni_real_generator(); }
00029 };
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines