![]() |
Humble Framework for SkyOS |
#include <HRandom.h>
Inheritance diagram for HRandom:

It is "designed with consideration of the flaws of various existing generators," has a period of 2^19937 - 1, gives a sequence that is 623-dimensionally equidistributed, and "has passed many stringent tests, including the die-hard test of G. Marsaglia and the load test of P. Hellekalek and S. Wegenkittl." It is efficient in memory usage (typically using 2506 to 5012 bytes of static data) and the code is quite short as well). It generates random numbers in batches of 624 at a time, so the caching and pipelining of modern systems is exploited. It is also divide- and mod-free.
We initialize m_uState[0..(N-1)] via the generator
x_new = (69069 * x_old) mod 2^32
from Line 15 of Table 1, p. 106, Sec. 3.3.4 of Knuth Volume 2, 3rd ed. The generator's potency (min. s>=0 with (69069-1)^s = 0 mod 2^32) is 16, which seems to be alright by p. 25, Sec. 3.2.1.3 of Knuth. It also does well in the dimension 2..5 spectral tests, but it could be better in dimension 6 (Line 15, Table 1, p. 106, Sec. 3.3.4, Knuth).
Note that the random number user does not see the values generated here directly since reload() will always munge them first, so maybe none of all of this matters. In fact, the seed values made here could even be extra-special desirable if the Mersenne Twister theory says so--that's why the only change made is to restrict to odd seeds.
Definition at line 57 of file HRandom.h.
Public Member Functions | |
| HRandom (uint32 uSeed=0) | |
| uint32 | Get (void) |
| Generates a random 32-bit value. | |
| uint32 | Get (uint32 uMax) |
| Generate a random 32-bit value within a specific range. | |
| int32 | Get (uint32 uCount, uint32 uDieSize, int32 nBonus=0) |
| Generate a random 32-bit value within a specific range. | |
| uint32 | GetSeed (void) const |
| Returns the seed value used to seed the random number generator. | |
| ErrCode | SetSeed (uint32 uSeed) |
| Seeds the random number generator. | |
Protected Member Functions | |
| uint32 | reload (void) |
| Computes the next set of random values. | |
Protected Attributes | |
| int32 | m_nLeft |
| Values remaining before reloading. | |
| uint32 | m_uSeed |
| Original seed value. | |
| uint32 * | m_puNext |
| Ptr to next random value. | |
| uint32 | m_uState [kLength+1] |
| State vector. | |
|
|
|
|
|
|
|
|
|
|
||||||||||||||||
|
This version of Get() is specifically designed to make "dice rolling" easier. For example, calling Get(4, 8, +1) would be the same as rolling four 8-sided dice, adding 1 to each roll, and summing the result; this would be "4d8+1" in FRP parlance. Note that unlike the other versions of Get(), this method can return a negative value if, and only if, the bonus/penalty parameter is negative.
|
|
|
|
|
|
|
2006.01.09-16:37