OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions
OpenXcom::RNG Namespace Reference

Random Number Generator used throughout the game for all your randomness needs. More...

Functions

uint64_t getSeed ()
 Returns the current seed in use by the generator. More...
 
void setSeed (uint64_t n)
 Changes the current seed in use by the generator. More...
 
int generate (int min, int max)
 Generates a random integer number within a certain range. More...
 
double generate (double min, double max)
 Generates a random decimal number within a certain range. More...
 
double boxMuller (double m, double s)
 Normal random variate generator. More...
 
bool percent (int value)
 Generates a random percent chance of an event occuring, and returns the result. More...
 
int generateEx (int max)
 Generates a random positive integer up to a number. More...
 
template<typename T >
void shuffle (T &list)
 Shuffles a list randomly. More...
 

Detailed Description

Random Number Generator used throughout the game for all your randomness needs.

Uses a 64-bit xorshift pseudorandom number generator.

Function Documentation

double OpenXcom::RNG::boxMuller ( double  m,
double  s 
)

Normal random variate generator.

Get normally distributed value.

Parameters
mmean
sstandard deviation
Returns
normally distributed value.
int OpenXcom::RNG::generate ( int  min,
int  max 
)

Generates a random integer number within a certain range.

Generates a random integer number, inclusive.

Parameters
minMinimum number, inclusive.
maxMaximum number, inclusive.
Returns
Generated number.
double OpenXcom::RNG::generate ( double  min,
double  max 
)

Generates a random decimal number within a certain range.

Generates a random floating-point number.

Parameters
minMinimum number.
maxMaximum number.
Returns
Generated number.
int OpenXcom::RNG::generateEx ( int  max)

Generates a random positive integer up to a number.

Generates a random integer number, exclusive.

Parameters
maxMaximum number, exclusive.
Returns
Generated number.
uint64_t OpenXcom::RNG::getSeed ( )

Returns the current seed in use by the generator.

Gets the seed in use.

Returns
Current seed.
bool OpenXcom::RNG::percent ( int  value)

Generates a random percent chance of an event occuring, and returns the result.

Generates a percentage chance.

Parameters
valueValue percentage (0-100%)
Returns
True if the chance succeeded.
void OpenXcom::RNG::setSeed ( uint64_t  n)

Changes the current seed in use by the generator.

Sets the seed in use.

Parameters
nNew seed.
template<typename T >
void OpenXcom::RNG::shuffle ( T &  list)

Shuffles a list randomly.

Randomly changes the orders of the elements in a list.

Parameters
listThe container to randomize.