|
OpenTTD Source
14.0-beta1
|
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_t
Next(uint32_t limit);
61 # define OTTD_Random() DoRandom(__LINE__, __FILE__)
63 # define Random() DoRandom(__LINE__, __FILE__)
65 uint32_t DoRandom(
int line,
const char *file);
66 # define RandomRange(limit) DoRandomRange(limit, __LINE__, __FILE__)
67 uint32_t DoRandomRange(uint32_t limit,
int line,
const char *file);
69 static inline uint32_t Random()
87 inline uint32_t InteractiveRandom()
92 inline uint32_t InteractiveRandomRange(uint32_t limit)
112 inline bool Chance16I(
const uint a,
const uint b,
const uint32_t r)
115 return (((uint16_t)r * b + b / 2) >> 16) < a;
129 # define Chance16(a, b) Chance16I(a, b, DoRandom(__LINE__, __FILE__))
153 # define Chance16R(a, b, r) (r = DoRandom(__LINE__, __FILE__), Chance16I(a, b, r))
155 inline bool Chance16R(
const uint a,
const uint b, uint32_t &r)
Randomizer _random
Random used in the game state calculations.
Stores the state of all random number generators.
void SaveRandomSeeds(SavedRandomSeeds *storage)
Saves the current seeds.
bool Chance16(const uint a, const uint b)
Flips a coin with given probability.
static uint32_t RandomRange(uint32_t limit)
Pick a random number between 0 and limit - 1, inclusive.
Randomizer _interactive_random
Random used everywhere else, where it does not (directly) influence the game state.
void SetSeed(uint32_t seed)
(Re)set the state of the random number generator.
uint32_t Next()
Generate the next pseudo random number.
bool Chance16I(const uint a, const uint b, const uint32_t r)
Checks if a given randomize-number is below a given probability.
Structure to encapsulate the pseudo random number generators.
void RestoreRandomSeeds(const SavedRandomSeeds &storage)
Restores previously saved seeds.
uint32_t state[2]
The state of the randomizer.
bool Chance16R(const uint a, const uint b, uint32_t &r)
Flips a coin with a given probability and saves the randomize-number in a variable.
void RandomBytesWithFallback(std::span< uint8_t > buf)
Fill the given buffer with random bytes.
void SetRandomSeed(uint32_t seed)
(Re)set the state of the random number generators.