MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / SeedModChance

Function SeedModChance

src/townname.cpp:178–190  ·  view source on GitHub ↗

* Generates a number from given seed. Uses different algorithm than SeedChance(). * @param shift_by number of bits seed is shifted to the right * @param max generated number is in interval 0...max-1 * @param seed seed * @return seed transformed to a number from given range */

Source from the content-addressed store, hash-verified

176 * @return seed transformed to a number from given range
177 */
178static inline uint32_t SeedModChance(uint8_t shift_by, size_t max, uint32_t seed)
179{
180 /* This actually gives *MUCH* more even distribution of the values
181 * than SeedChance(), which is absolutely horrible in that. If
182 * you do not believe me, try with i.e. the Czech town names,
183 * compare the words (nicely visible on prefixes) generated by
184 * SeedChance() and SeedModChance(). Do not get discouraged by the
185 * never-use-modulo myths, which hold true only for the linear
186 * congruential generators (and Random() isn't such a generator).
187 * --pasky
188 * TODO: Perhaps we should use it for all the name generators? --pasky */
189 return (seed >> shift_by) % max;
190}
191
192
193/**

Callers 4

MakeCzechTownNameFunction · 0.85
MakeTurkishTownNameFunction · 0.85
MakeItalianTownNameFunction · 0.85
MakeCatalanTownNameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected