Functions to generate pseudo-random numbers
| 19 | |
| 20 | /// Functions to generate pseudo-random numbers |
| 21 | class Random { |
| 22 | public: |
| 23 | class UnrepeatedRandomizer; |
| 24 | |
| 25 | public: |
| 26 | /** |
| 27 | * Sets the random number seed to the current time |
| 28 | */ |
| 29 | static void SeedRand(); |
| 30 | |
| 31 | /** |
| 32 | * Sets the random number seed to the current time only the first |
| 33 | * time this function is called |
| 34 | */ |
| 35 | static void SeedRandOnce(); |
| 36 | |
| 37 | /** |
| 38 | * Sets the given random number seed |
| 39 | * @param seed |
| 40 | */ |
| 41 | static void SeedRand(int seed); |
| 42 | |
| 43 | /** |
| 44 | * Sets the given random number seed only the first time this function |
| 45 | * is called |
| 46 | * @param seed |
| 47 | */ |
| 48 | static void SeedRandOnce(int seed); |
| 49 | |
| 50 | /** |
| 51 | * Returns a random number in the range [0..1] |
| 52 | * @return random T number in [0..1] |
| 53 | */ |
| 54 | template <class T> |
| 55 | static T RandomValue() { |
| 56 | return (T)rand() / (T)RAND_MAX; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns a random number in the range [min..max] |
| 61 | * @param min |
| 62 | * @param max |
| 63 | * @return random T number in [min..max] |
| 64 | */ |
| 65 | template <class T> |
| 66 | static T RandomValue(T min, T max) { |
| 67 | return Random::RandomValue<T>() * (max - min) + min; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns a random int in the range [min..max] |
| 72 | * @param min |
| 73 | * @param max |
| 74 | * @return random int in [min..max] |
| 75 | */ |
| 76 | static int RandomInt(int min, int max); |
| 77 | |
| 78 | /** |
no outgoing calls