![]() |
Knight's Tour Generator
Tourneys and the Fast Generation and Obfuscation of Closed Knight's Tours
|
Pseudorandom number generator (PRNG for short). More...
#include <Random.h>
Public Member Functions | |
CRandom () | |
Constructor. | |
void | srand () |
Seed the random number generator. More... | |
UINT | randn () |
Get a random unsigned integer. More... | |
UINT | randn (UINT i, UINT j) |
Get random number in \([i,j]\). More... | |
float | randf () |
Get a random floating point number. More... | |
void | randclr (UINT rgb[3]) |
Get a random color. More... | |
Private Attributes | |
UINT | m_uState [4] = {0} |
Current state. | |
A pseudorandom number generator based on xorshift128. It seeds itself with the C standard rand() function, which it assumes has been seeded with something that is different each time that the program is run such as the Windows API function timeGetTime().
void CRandom::randclr | ( | UINT | rgb[3] | ) |
Generate a (hopefully) aesthetically pleasing pseudorandom color by generating a color in HSV format with a random hue, then converting that to RGB format. HSV is used because colors are better distributed in HSV-space than in RGB-space. The colors generated are reasonable dark and highly unlikely to be gray.
rgb | [out] An aesthetically pleasing pseudorandom RGB color. |
Definition at line 97 of file Random.cpp.
float CRandom::randf | ( | ) |
Generate a pseudorandom floating positive point number in \([0,1]\) by generating a pseudorandom unsigned integer and dividing it by \(2^{32} - 1\). Although the result is a float, the internal calculation here is done with doubles to avoid loss of precision (UINT ints have 32 bits but floats have only a 24-bit mantissa). The results are scattered within \([0,1]\) but the randomness is limited by the fact that floats are not randomly distributed in \([0,1]\) to begin with.
Definition at line 86 of file Random.cpp.
UINT CRandom::randn | ( | ) |
Generate a pseudorandom unsigned integer using xorshift128. This is the one that does the actual work here: The other pseudorandom generation functions rely on this one. Algorithm snarfed from the interwebs.
Definition at line 49 of file Random.cpp.
Generate a pseudorandom unsigned integer within a range.
i | Bottom of range. |
j | Top of range. |
Definition at line 72 of file Random.cpp.
void CRandom::srand | ( | ) |
Seed the pseudorandom number generator by using the linear congruential pseudorandom number generator rand(), which we assume has been seeded from the current time.
Definition at line 39 of file Random.cpp.