diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-09-02 14:11:59 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-09-02 14:11:59 +0000 |
| commit | 7cbe5a79346df9c045ac640e48f711610a4852ca (patch) | |
| tree | 7ca572f3ffd4d1d0131189373bd2faaa1cf60a72 /src/SimpleRandomizer.h | |
| parent | 9f5ed15e6f3a934c23ae636dac4c150d5e1d15e5 (diff) | |
2008-09-02 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Moved implementation to SimpleRandomizer.cc from
SimpleRandomizer.h.
Added return value of getpid() to argument of srand() to achieve
more
randomized value.
* src/SimpleRandomizer.cc
* src/SimpleRandomizer.h
Diffstat (limited to 'src/SimpleRandomizer.h')
| -rw-r--r-- | src/SimpleRandomizer.h | 34 |
1 files changed, 9 insertions, 25 deletions
diff --git a/src/SimpleRandomizer.h b/src/SimpleRandomizer.h index 26d281a2..4d732fbc 100644 --- a/src/SimpleRandomizer.h +++ b/src/SimpleRandomizer.h @@ -36,46 +36,30 @@ #define _D_SIMPLE_RANDOMIZER_H_ #include "Randomizer.h" -#include "a2time.h" -#include <stdlib.h> namespace aria2 { class SimpleRandomizer : public Randomizer { private: - static RandomizerHandle randomizer; + static SharedHandle<Randomizer> _randomizer; - SimpleRandomizer() {} + SimpleRandomizer(); public: - - static RandomizerHandle getInstance() { - if(randomizer.isNull()) { - randomizer.reset(new SimpleRandomizer()); - } - return randomizer; - } - static void init() { - srand(time(0)); - } + static SharedHandle<Randomizer> getInstance(); + + static void init(); - virtual ~SimpleRandomizer() {} + virtual ~SimpleRandomizer(); - virtual long int getRandomNumber() { - return rand(); - } + virtual long int getRandomNumber(); - virtual long int getMaxRandomNumber() { - return RAND_MAX; - } + virtual long int getMaxRandomNumber(); /** * Returns random number in [0, to). */ - virtual long int getRandomNumber(long int to) - { - return(int32_t)(((double)to)*getRandomNumber()/(getMaxRandomNumber()+1.0)); - } + virtual long int getRandomNumber(long int to); }; } // namespace aria2 |
