12 #ifndef RANDOM_FUNC_HPP 13 #define RANDOM_FUNC_HPP 15 #if defined(__APPLE__) 17 #define Random OTTD_Random 28 uint32
Next(uint32 limit);
56 _random = storage.random;
57 _interactive_random = storage.interactive_random;
63 #define OTTD_Random() DoRandom(__LINE__, __FILE__) 65 #define Random() DoRandom(__LINE__, __FILE__) 67 uint32 DoRandom(
int line,
const char *file);
68 #define RandomRange(limit) DoRandomRange(limit, __LINE__, __FILE__) 69 uint32 DoRandomRange(uint32 limit,
int line,
const char *file);
71 static inline uint32 Random()
73 return _random.
Next();
85 return _random.
Next(limit);
89 static inline uint32 InteractiveRandom()
91 return _interactive_random.
Next();
94 static inline uint32 InteractiveRandomRange(uint32 limit)
96 return _interactive_random.
Next(limit);
114 static inline bool Chance16I(
const uint a,
const uint b,
const uint32 r)
117 return (((uint16)r * b + b / 2) >> 16) < a;
131 #define Chance16(a, b) Chance16I(a, b, DoRandom(__LINE__, __FILE__)) 133 static inline bool Chance16(
const uint a,
const uint b)
155 #define Chance16R(a, b, r) (r = DoRandom(__LINE__, __FILE__), Chance16I(a, b, r)) 157 static inline bool Chance16R(
const uint a,
const uint b, uint32 &r)
static bool Chance16I(const uint a, const uint b, const uint32 r)
Checks if a given randomize-number is below a given probability.
Stores the state of all random number generators.
static void RestoreRandomSeeds(const SavedRandomSeeds &storage)
Restores previously saved seeds.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
void SetSeed(uint32 seed)
(Re)set the state of the random number generator.
Randomizer _interactive_random
Random used every else where is does not (directly) influence the game state.
static bool Chance16R(const uint a, const uint b, uint32 &r)
Flips a coin with a given probability and saves the randomize-number in a variable.
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
Randomizer _random
Random used in the game state calculations.
void SetRandomSeed(uint32 seed)
(Re)set the state of the random number generators.
uint32 Next()
Generate the next pseudo random number.
static void SaveRandomSeeds(SavedRandomSeeds *storage)
Saves the current seeds.
uint32 state[2]
The state of the randomizer.
Structure to encapsulate the pseudo random number generators.