diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-05-22 16:57:15 +0000 | 
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-05-22 16:57:15 +0000 | 
| commit | 2295579eb790d6eff6e54e84c01da6de10809a71 (patch) | |
| tree | 3d8282dedc137fee009f71ff904370537009e504 /src/experimental/random.h | |
| parent | 690ad7280e655654a3bcca2ca5ced9caacf75c8b (diff) | |
| download | libbu++-2295579eb790d6eff6e54e84c01da6de10809a71.tar.gz libbu++-2295579eb790d6eff6e54e84c01da6de10809a71.tar.bz2 libbu++-2295579eb790d6eff6e54e84c01da6de10809a71.tar.xz libbu++-2295579eb790d6eff6e54e84c01da6de10809a71.zip | |
Better win_o ignores.  The random number system is pretty much together.
We need a few extra helper functions to cover some other good things, like
normalized floating point numbers, etc.
Diffstat (limited to '')
| -rw-r--r-- | src/experimental/random.h | 51 | 
1 files changed, 51 insertions, 0 deletions
| diff --git a/src/experimental/random.h b/src/experimental/random.h index c792772..ba26f21 100644 --- a/src/experimental/random.h +++ b/src/experimental/random.h | |||
| @@ -4,5 +4,56 @@ | |||
| 4 | * This file is part of the libbu++ library and is released under the | 4 | * This file is part of the libbu++ library and is released under the | 
| 5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. | 
| 6 | */ | 6 | */ | 
| 7 | #ifndef BU_RANDOM_H | ||
| 8 | #define BU_RANDOM_H | ||
| 7 | 9 | ||
| 10 | #include "bu/singleton.h" | ||
| 11 | #include <stdint.h> | ||
| 12 | |||
| 13 | namespace Bu | ||
| 14 | { | ||
| 15 | class RandomBase; | ||
| 16 | class Random : public Bu::Singleton<Bu::Random> | ||
| 17 | { | ||
| 18 | friend class Bu::Singleton<Bu::Random>; | ||
| 19 | private: | ||
| 20 | Random(); | ||
| 21 | virtual ~Random(); | ||
| 22 | |||
| 23 | public: | ||
| 24 | template<typename cl> | ||
| 25 | static void setGenerator() | ||
| 26 | { | ||
| 27 | delete getInstance().pGen; | ||
| 28 | getInstance().pGen = new cl(); | ||
| 29 | } | ||
| 30 | |||
| 31 | template<typename cl, typename t1> | ||
| 32 | static void setGenerator( t1 p1 ) | ||
| 33 | { | ||
| 34 | delete getInstance().pGen; | ||
| 35 | getInstance().pGen = new cl( p1 ); | ||
| 36 | } | ||
| 37 | |||
| 38 | template<typename cl, typename t1, typename t2> | ||
| 39 | static void setGenerator( t1 p1, t2 p2 ) | ||
| 40 | { | ||
| 41 | delete getInstance().pGen; | ||
| 42 | getInstance().pGen = new cl( p1, p2 ); | ||
| 43 | } | ||
| 44 | |||
| 45 | RandomBase &getGenerator() { return *pGen; } | ||
| 46 | |||
| 47 | static int32_t rand(); | ||
| 48 | static void seed( int32_t iSeed ); | ||
| 49 | |||
| 50 | private: | ||
| 51 | void checkInit(); | ||
| 52 | |||
| 53 | private: | ||
| 54 | Bu::RandomBase *pGen; | ||
| 55 | }; | ||
| 56 | }; | ||
| 57 | |||
| 58 | #endif | ||
| 8 | 59 | ||
