/* */ #ifndef _D_SIMPLE_RANDOMIZER_H_ #define _D_SIMPLE_RANDOMIZER_H_ #include "Randomizer.h" #include "a2time.h" #include namespace aria2 { class SimpleRandomizer : public Randomizer { private: static RandomizerHandle randomizer; SimpleRandomizer() {} public: static RandomizerHandle getInstance() { if(randomizer.isNull()) { randomizer.reset(new SimpleRandomizer()); } return randomizer; } static void init() { srand(time(0)); } virtual ~SimpleRandomizer() {} virtual long int getRandomNumber() { return rand(); } virtual long int getMaxRandomNumber() { return RAND_MAX; } /** * Returns random number in [0, to). */ virtual long int getRandomNumber(long int to) { return(int32_t)(((double)to)*getRandomNumber()/(getMaxRandomNumber()+1.0)); } }; } // namespace aria2 #endif // _D_SIMPLE_RANDOMIZER_H_