Rev | Line | |
---|
[216] | 1 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | /** |
---|
| 3 | * Contains code for random generators. |
---|
| 4 | * \file IceRandom.h |
---|
| 5 | * \author Pierre Terdiman |
---|
| 6 | * \date August, 9, 2001 |
---|
| 7 | */ |
---|
| 8 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 9 | |
---|
| 10 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 11 | // Include Guard |
---|
| 12 | #ifndef __ICERANDOM_H__ |
---|
| 13 | #define __ICERANDOM_H__ |
---|
| 14 | |
---|
| 15 | FUNCTION ICECORE_API void SRand(udword seed); |
---|
| 16 | FUNCTION ICECORE_API udword Rand(); |
---|
| 17 | |
---|
| 18 | //! Returns a unit random floating-point value |
---|
| 19 | inline_ float UnitRandomFloat() { return float(Rand()) * ONE_OVER_RAND_MAX; } |
---|
| 20 | |
---|
| 21 | //! Returns a random index so that 0<= index < max_index |
---|
| 22 | ICECORE_API udword GetRandomIndex(udword max_index); |
---|
| 23 | |
---|
| 24 | class ICECORE_API BasicRandom |
---|
| 25 | { |
---|
| 26 | public: |
---|
| 27 | |
---|
| 28 | //! Constructor |
---|
| 29 | inline_ BasicRandom(udword seed=0) : mRnd(seed) {} |
---|
| 30 | //! Destructor |
---|
| 31 | inline_ ~BasicRandom() {} |
---|
| 32 | |
---|
| 33 | inline_ void SetSeed(udword seed) { mRnd = seed; } |
---|
| 34 | inline_ udword GetCurrentValue() const { return mRnd; } |
---|
| 35 | inline_ udword Randomize() { mRnd = mRnd * 2147001325 + 715136305; return mRnd; } |
---|
| 36 | |
---|
| 37 | private: |
---|
| 38 | udword mRnd; |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | #endif // __ICERANDOM_H__ |
---|
| 42 | |
---|
Note: See
TracBrowser
for help on using the repository browser.