ScummVM
Common::RandomSource Class Reference

Simple random number generator. More...

#include <random.h>

Public Member Functions

 RandomSource (const String &name)
 Construct a new randomness source with the specific name. More...
 
void setSeed (uint32 seed)
 
uint32 getSeed () const
 
uint getRandomNumber (uint max)
 Generates a random unsigned integer in the interval [0, max]. More...
 
uint getRandomBit ()
 Generates a random bit, i.e. More...
 
uint getRandomNumberRng (uint min, uint max)
 Generates a random unsigned integer in the interval [min, max]. More...
 

Private Attributes

uint32 _randSeed
 

Detailed Description

Simple random number generator.

Although it is definitely not suitable for cryptographic purposes, it serves our purposes just fine.

Definition at line 36 of file random.h.

Constructor & Destructor Documentation

◆ RandomSource()

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

Construct a new randomness source with the specific name.

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

Definition at line 30 of file random.cpp.

Member Function Documentation

◆ getRandomBit()

uint Common::RandomSource::getRandomBit ( )

Generates a random bit, i.e.

either 0 or 1. Identical to getRandomNumber(1), but potentially faster.

Returns
a random bit, either 0 or 1

Definition at line 52 of file random.cpp.

◆ getRandomNumber()

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

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

Parameters
maxthe upper bound
Returns
a random number in the interval [0, max]

Definition at line 46 of file random.cpp.

◆ getRandomNumberRng()

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

Generates 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]

Definition at line 58 of file random.cpp.

◆ getSeed()

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

Definition at line 51 of file random.h.

◆ setSeed()

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

Definition at line 42 of file random.cpp.

Member Data Documentation

◆ _randSeed

uint32 Common::RandomSource::_randSeed
private

Definition at line 38 of file random.h.


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