![]() |
SAGE
A Simple Academic Game Engine
|
A Pseudorandom Number Generator (PRNG for short). More...
#include <SageRandom.h>


Public Member Functions | |
| CRandom () | |
| Constructor. | |
| void | srand (UINT) |
| Seed the random number generator. | |
| void | srand () |
| Seed the random number generator. | |
| UINT | randn () |
| Get a random unsigned integer. | |
| UINT | randn (UINT, UINT) |
| Get random integer in \([i,j]\). | |
| float | randf () |
| Get a random floating point number. | |
| Vector2 | randv () |
| Get a random 2D direction. | |
| Vector3 | randv3 () |
| Get a random 3D direction. | |
| XMFLOAT4 | randclr () |
| Get a random color. | |
Private Attributes | |
| std::default_random_engine | m_stdRandom |
| Pseudo-random number generator. | |
Additional Inherited Members | |
Static Protected Attributes inherited from Sage::CComponent | |
| static std::unique_ptr< CTimer > | m_pTimer = std::make_unique<CTimer>() |
| Pointer to a timer. | |
| static std::unique_ptr< CRandom > | m_pRandom = std::make_unique<CRandom>() |
| Pointer to a PRNG. | |
| static std::unique_ptr< CSound > | m_pSound = std::make_unique<CSound>() |
| Pointer to sound manager. | |
| static std::unique_ptr< CKeyboard > | m_pKeyboard |
| Pointer to a keyboard handler. | |
| static std::unique_ptr< CMouse > | m_pMouse = std::make_unique<CMouse>() |
| Pointer to a mouse handler. | |
| static std::unique_ptr< CController > | m_pController |
| Pointer to a controller. | |
CRandom is a simple pseudo-random number generator. It can be seeded with the time or, if reproducability is desired (eg. when debugging), with a fixed seed. It has functions for generating pseudo-random unsigned integers, floats, unit vectors, and colors.
| CRandom::CRandom | ( | ) |
The constructor seeds the pseudo-random number generator, just in case the programmer forgets to do it.

| XMFLOAT4 CRandom::randclr | ( | ) |
Generate an aesthetically pleasing pseudo-random color by generating a color in HSV format with random hue, saturation 0.5, and value 1.0 and then converting that to RGB. HSV is used because colors are better distributed in HSV-space than in RGB-space. There will probably be a lot of repeated colors generated by this function but probably not consecutively. The colors generated will be light and bright highly unlikely to be gray. The alpha channel is set to 1, that is, there is no transparency.

| float CRandom::randf | ( | ) |
Generate a pseudo-random floating positive point number in \([0,1]\).

| UINT CRandom::randn | ( | ) |
Generate a pseudo-random unsigned integer.
| UINT CRandom::randn | ( | UINT | i, |
| UINT | j ) |
Generate a pseudo-random unsigned integer within a given range.
| i | Bottom of range. |
| j | Top of range. |
| Vector2 CRandom::randv | ( | ) |
Generate a pseudo-random unit 2D vector by generating an angle in the range \([0, 2\pi]\) and returning the unit vector with that orientation.

| Vector3 CRandom::randv3 | ( | ) |
Generate a pseudo-random unit 3D vector from a uniform spherical distribution. Algorithm from http://stackoverflow.com/questions/5408276/python-uniform-spherical-distribution

| void CRandom::srand | ( | ) |
Seed the pseudo-random number generator with the Unix epoch time (number of seconds since Jan 1, 1970 UTC, excluding leap seconds).


| void CRandom::srand | ( | UINT | n | ) |
Seed the pseudo-random number generator.
| n | The seed value. |