![]() |
Lindenmayer System
A Simple L-system Image Generator Featuring Turtle Graphics
|
Pseudorandom Number Generator (PRNG for short). More...
#include <Random.h>
Public Member Functions | |
| CRandom () | |
| Constructor. More... | |
| void | srand (int seed=-1) |
| Seed the random number generator. More... | |
| UINT | randn () |
| Get random unsigned integer. More... | |
| UINT | randn (UINT i, UINT j) |
| Get random integer in \([i,j]\). More... | |
| float | randf () |
| Get random floating point number. More... | |
Private Attributes | |
| UINT | m_uState [4] |
| Current state. | |
A simple pseudorandom number generator based on xorshift128. It can be seeded with the time or, if reproducability is desired (eg. when debugging), with a fixed seed.
| CRandom::CRandom | ( | ) |
Seed the PRNG with an unpredictable value drawn from a timer. Call srand() later to override this.
Definition at line 40 of file Random.cpp.
| float CRandom::randf | ( | ) |
Generate a pseudorandom floating positive point number in \([0,1]\)by generatings a pseudorandom unsigned integer and dividing it by \(2^{32} - 1\).
Definition at line 104 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 it to do the heavy lifting. Algorithm snarfed from the interwebs someplace, I don't quite remember where.
Definition at line 72 of file Random.cpp.
| UINT CRandom::randn | ( | UINT | i, |
| UINT | j | ||
| ) |
Generate a pseudorandom unsigned integer within a range.
| i | Bottom of range. |
| j | Top of range. |
Definition at line 95 of file Random.cpp.
| void CRandom::srand | ( | int | seed = -1 | ) |
If the seed is negative (which it is by default if no parameter is supplied), then use timeGetTime instead (which is, one hopes, unpredictable). The state variables for xorshift128 are initialized using the C Standard Library function rand() seeded using the pro-offered seed value.
| seed | The seed, defaults to -1. |
Definition at line 50 of file Random.cpp.
1.8.14