diff options
| author | treeston <treeston.mmoc@gmail.com> | 2015-11-28 19:21:33 +0100 |
|---|---|---|
| committer | treeston <treeston.mmoc@gmail.com> | 2015-11-28 23:53:04 +0100 |
| commit | c0faee079542c134925025a3c32c9324e750dfaa (patch) | |
| tree | 2e76557d613fd2b41c4d46dc99ca5dfa22a88da3 /src | |
| parent | e266278f7d029f1547b1ae3228d658463c69da09 (diff) | |
Core/Util: Add a urandms(min,max) helper to make urand(min*IN_MILLISECONDS, max*IN_MILLISECONDS) shorter to write for random time intervals (boss scripts).
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/Utilities/Util.cpp | 7 | ||||
| -rw-r--r-- | src/common/Utilities/Util.h | 3 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index 33c273fb05f..9f61dd12e4c 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -58,6 +58,13 @@ uint32 urand(uint32 min, uint32 max) return GetRng()->URandom(min, max); } +uint32 urandms(uint32 min, uint32 max) +{ + ASSERT(max >= min); + ASSERT(INT_MAX/IN_MILLISECONDS >= max); + return GetRng()->URandom(min * IN_MILLISECONDS, max * IN_MILLISECONDS); +} + float frand(float min, float max) { ASSERT(max >= min); diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index 6a872b44a60..b748e83408b 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -82,6 +82,9 @@ int32 irand(int32 min, int32 max); /* Return a random number in the range min..max (inclusive). */ uint32 urand(uint32 min, uint32 max); +/* Return a random millisecond value between min and max seconds. Functionally equivalent to urand(min*IN_MILLISECONDS, max*IN_MILLISECONDS). */ +uint32 urandms(uint32 min, uint32 max); + /* Return a random number in the range 0 .. UINT32_MAX. */ uint32 rand32(); |
