Mercurial > hg > openttd
diff src/core/random_func.cpp @ 17148:848eb1ffb17d draft
(svn r21886) -Codechange: move documentation towards the code to make it more likely to be updated [n].
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 22 Jan 2011 09:53:15 +0000 |
parents | 3f22783849da |
children | 1899a18cc2d7 |
line wrap: on
line diff
--- a/src/core/random_func.cpp +++ b/src/core/random_func.cpp @@ -15,6 +15,10 @@ Randomizer _random, _interactive_random; +/** + * Generate the next pseudo random number + * @return the random number + */ uint32 Randomizer::Next() { const uint32 s = this->state[0]; @@ -24,17 +28,30 @@ return this->state[1] = ROR(s, 3) - 1; } +/** + * Generate the next pseudo random number scaled to max + * @param max the maximum value of the returned random number + * @return the random number + */ uint32 Randomizer::Next(uint32 max) { return ((uint64)this->Next() * (uint64)max) >> 32; } +/** + * (Re)set the state of the random number generator. + * @param seed the new state + */ void Randomizer::SetSeed(uint32 seed) { this->state[0] = seed; this->state[1] = seed; } +/** + * (Re)set the state of the random number generators. + * @param seed the new state + */ void SetRandomSeed(uint32 seed) { _random.SetSeed(seed);