MCPcopy Create free account
hub / github.com/SimHacker/micropolis / getRandom

Method getRandom

MicropolisCore/src/MicropolisEngine/src/random.cpp:100–113  ·  view source on GitHub ↗

* Draw a random number in a given range. * @param range Upper bound of the range (inclusive). * @return Random number between \c 0 and \a range (inclusive). */

Source from the content-addressed store, hash-verified

98 * @return Random number between \c 0 and \a range (inclusive).
99 */
100short Micropolis::getRandom(short range)
101{
102 int maxMultiple, rnum;
103
104 range++; /// @bug Increment may cause range overflow.
105 maxMultiple = 0xffff / range;
106 maxMultiple *= range;
107
108 do {
109 rnum = getRandom16();
110 } while (rnum >= maxMultiple);
111
112 return (rnum % range);
113}
114
115
116/**

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected