* 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 */
| 176 | * @return seed transformed to a number from given range |
| 177 | */ |
| 178 | static 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 | /** |
no outgoing calls
no test coverage detected