OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #ifndef RANDOM_FUNC_HPP
11 #define RANDOM_FUNC_HPP
13 #if defined(__APPLE__)
15 # define Random OTTD_Random
26 uint32
Next(uint32 limit);
61 # define OTTD_Random() DoRandom(__LINE__, __FILE__)
63 # define Random() DoRandom(__LINE__, __FILE__)
65 uint32 DoRandom(
int line,
const char *file);
66 # define RandomRange(limit) DoRandomRange(limit, __LINE__, __FILE__)
67 uint32 DoRandomRange(uint32 limit,
int line,
const char *file);
69 static inline uint32 Random()
87 static inline uint32 InteractiveRandom()
92 static inline uint32 InteractiveRandomRange(uint32 limit)
112 static inline bool Chance16I(
const uint a,
const uint b,
const uint32 r)
115 return (((uint16)r * b + b / 2) >> 16) < a;
129 # define Chance16(a, b) Chance16I(a, b, DoRandom(__LINE__, __FILE__))
131 static inline bool Chance16(
const uint a,
const uint b)
153 # define Chance16R(a, b, r) (r = DoRandom(__LINE__, __FILE__), Chance16I(a, b, r))
155 static inline bool Chance16R(
const uint a,
const uint b, uint32 &r)
static bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
uint32 Next()
Generate the next pseudo random number.
Randomizer _random
Random used in the game state calculations.
Stores the state of all random number generators.
void SetRandomSeed(uint32 seed)
(Re)set the state of the random number generators.
static void SaveRandomSeeds(SavedRandomSeeds *storage)
Saves the current seeds.
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
static bool Chance16I(const uint a, const uint b, const uint32 r)
Checks if a given randomize-number is below a given probability.
static void RestoreRandomSeeds(const SavedRandomSeeds &storage)
Restores previously saved seeds.
Randomizer _interactive_random
Random used everywhere else, where it does not (directly) influence the game state.
uint32 state[2]
The state of the randomizer.
Structure to encapsulate the pseudo random number generators.
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.
void SetSeed(uint32 seed)
(Re)set the state of the random number generator.