ScummVM API documentation
Common::RandomSource Class Reference

#include <random.h>

Public Member Functions

 RandomSource (const String &name)
 
void setSeed (uint32 seed)
 
uint32 getSeed () const
 
uint getRandomNumber (uint max)
 
uint getRandomBit ()
 
uint getRandomNumberRng (uint min, uint max)
 
int getRandomNumberRngSigned (int min, int max)
 

Static Public Member Functions

static uint32 generateNewSeed ()
 

Detailed Description

Xorshift* random number generator. Although it is definitely not suitable for cryptographic purposes, it serves our purposes just fine.

Constructor & Destructor Documentation

◆ RandomSource()

Common::RandomSource::RandomSource ( const String name)

Construct a new randomness source with the specific name. The name used must be globally unique, and is used to register the randomness source with the active event recorder, if any.

Member Function Documentation

◆ generateNewSeed()

static uint32 Common::RandomSource::generateNewSeed ( )
static

Generates new seed based on the current date/time

◆ setSeed()

void Common::RandomSource::setSeed ( uint32  seed)

Set the seed used to initialize the RNG.

◆ getSeed()

uint32 Common::RandomSource::getSeed ( ) const
inline

< Get a random seed that can be used to initialize the RNG.

◆ getRandomNumber()

uint Common::RandomSource::getRandomNumber ( uint  max)

Generate a random unsigned integer in the interval [0, max].

Parameters
maxThe upper bound
Returns
A random number in the interval [0, max].

◆ getRandomBit()

uint Common::RandomSource::getRandomBit ( )

Generate a random bit, i.e. either 0 or 1. Identical to getRandomNumber(1), but potentially faster.

Returns
A random bit, either 0 or 1.

◆ getRandomNumberRng()

uint Common::RandomSource::getRandomNumberRng ( uint  min,
uint  max 
)

Generate a random unsigned integer in the interval [min, max].

Parameters
minThe lower bound.
maxThe upper bound.
Returns
A random number in the interval [min, max].

◆ getRandomNumberRngSigned()

int Common::RandomSource::getRandomNumberRngSigned ( int  min,
int  max 
)

Generates a random signed integer in the interval [min, max].

Parameters
minthe lower bound
maxthe upper bound
Returns
a random number in the interval [min, max]

The documentation for this class was generated from the following file: