Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
Burger::RandomBase Class Referenceabstract

A random number generator base class. More...

Inheritance diagram for Burger::RandomBase:
Inheritance graph
[legend]
Collaboration diagram for Burger::RandomBase:
Collaboration graph
[legend]

Public Member Functions

const Burger::StaticRTTIget_StaticRTTI (void) const noexcept override
 Get the description to the class.
 
virtual void set_seed (uint32_t uNewSeed) noexcept=0
 Seed the random number generator.
 
virtual uint32_t get (void) noexcept=0
 Return a 32 bit pseudo random number.
 
uint32_t get_seed (void) const noexcept
 Return the random number seed.
 
void random_seed (void) noexcept
 Seed with a random value.
 
uint32_t get_uint32 (uint32_t uRange) noexcept
 Return a 32 bit random number.
 
uint32_t get_dice (uint32_t uDiceCount, uint32_t uDiceSize) noexcept
 Return a dice roll.
 
int32_t get_int32 (uint32_t uRange) noexcept
 Return a signed value in a specific range.
 
float get_float (void) noexcept
 Return a float from 0.0f to 0.99999f.
 
float get_float (float fRange) noexcept
 Return a float from 0.0f to fRange.
 
float get_symmetric_float (void) noexcept
 Return a float from -.0.99999f to 0.99999f.
 
float get_symmetric_float (float fRange) noexcept
 Return a float from -fRange to fRange.
 
double get_double (void) noexcept
 Return a double from 0.0 to 0.999999999.
 
- Public Member Functions inherited from Burger::Base
const charget_class_name (void) const noexcept
 Get the name of the class.
 
virtual ~Base () noexcept=default
 Destructor.
 

Static Public Attributes

static const Burger::StaticRTTI g_StaticRTTI
 The global description of the class.
 
- Static Public Attributes inherited from Burger::Base
static const Burger::StaticRTTI g_StaticRTTI
 The global description of the class.
 

Protected Attributes

uint32_t m_uSeed
 Random number seed.
 

Detailed Description

A random number generator base class.


This class is what all random number generators derive from so that many random number generator algorithms can share common code.

Note
It's permissible to make binary copies of this class.

Member Function Documentation

◆ get()

Burger::RandomBase::get ( void )
pure virtualnoexcept

Return a 32 bit pseudo random number.


Get a pseudo random number using the current algorithm. Return a 32 bit unsigned value.

Returns
A 32 bit pseudo random number.
See also
set_seed(uint32_t) or get_uint32(uint32_t)

Implemented in Burger::Random, and Burger::RandomMersenneTwist.

◆ get_dice()

uint32_t BURGER_API Burger::RandomBase::get_dice ( uint32_t uDiceCount,
uint32_t uDiceSize )
noexcept

Return a dice roll.


Given the number of dice and the size of the dice, "roll" the dice and return the result.

Examples: get_dice(1,4) will yield 1-4 evenly spread get_dice(2,4) will yield 2-8 with 5 having the highest probability based on the curve

If either input value is 0, the result is zero.

If the dice roll exceeds a uint32_t, UINT32_MAX is returned

Parameters
uDiceCountNumber of dice to roll.
uDiceSizeNumber of sides on each die.
Returns
A random number generated by the dice roll.

◆ get_double()

double BURGER_API Burger::RandomBase::get_double ( void )
noexcept

Return a double from 0.0 to 0.999999999.


Returns a random number in the range of 0.0 to 0.999999. The numbers are spread evenly with 53 bit resolution.

Returns
Random double from 0.0 to 0.9999999999
See also
get_float() and get().

◆ get_float() [1/2]

float BURGER_API Burger::RandomBase::get_float ( float fRange)
noexcept

Return a float from 0.0f to fRange.


Returns a random number in the range of 0.0f to fRange. The numbers are spread evenly.

Returns
Random float from 0.0 to fRange
See also
get_float(void), get_int32(uint32_t), get_symmetric_float(float) and get_uint32(uint32_t).

◆ get_float() [2/2]

float BURGER_API Burger::RandomBase::get_float ( void )
noexcept

Return a float from 0.0f to 0.99999f.


Returns a random number in the range of 0.0f to 0.999999f. The numbers are spread evenly.

Returns
Random float from 0.0 to 0.9999999999f
See also
get_int32(uint32_t), get_symmetric_float() and get().

◆ get_int32()

int32_t BURGER_API Burger::RandomBase::get_int32 ( uint32_t uRange)
noexcept

Return a signed value in a specific range.


Return a random number between -Range and +Range (Inclusive) and it's a SIGNED value. If Range = 3, then the value returned is -2 to 2 inclusive. 0, and numbers higher than 0x7FFFFFFFU are illegal.

Parameters
uRangeRange from 1 to MAX_INT-1.
Returns
Signed value from -uRange to uRange (Inclusive)
See also
get() and get_float().

◆ get_seed()

uint32_t Burger::RandomBase::get_seed ( void ) const
inlinenoexcept

Return the random number seed.


Get seed value for this pseudo random number generator.

Returns
A 32 bit pseudo random number.
See also
set_seed(uint32_t)

◆ get_StaticRTTI()

const Burger::StaticRTTI * Burger::RandomBase::get_StaticRTTI ( void ) const
overridevirtualnoexcept

Get the description to the class.


This virtual function will pull the pointer to the StaticRTTI instance that has the name of the class. Due to it being virtual, it will be the name of the most derived class.

Returns
Pointer to a global, read only instance of StaticRTTI for the true class

Reimplemented from Burger::Base.

Reimplemented in Burger::RandomMersenneTwist.

◆ get_symmetric_float() [1/2]

float BURGER_API Burger::RandomBase::get_symmetric_float ( float fRange)
noexcept

Return a float from -fRange to fRange.


Returns a random number in the range of -fRange to fRange. The numbers are spread evenly.

Returns
Random float from -fRange to fRange
See also
get_symmetric_float(void), get_int32(uint32_t), get_float(float) and get_uint32(uint32_t).

◆ get_symmetric_float() [2/2]

float BURGER_API Burger::RandomBase::get_symmetric_float ( void )
noexcept

Return a float from -.0.99999f to 0.99999f.


Returns a random number in the range of -.0.99999f to 0.999999f. The numbers are spread evenly.

Returns
Random float from -.0.99999f to 0.9999999999f
See also
get_int32(uint32_t), get_float() and get().

◆ get_uint32()

uint32_t BURGER_API Burger::RandomBase::get_uint32 ( uint32_t uRange)
noexcept

Return a 32 bit random number.


Get a random number. Return a number between 0 through (Range-1) inclusive.

Parameters
uRange0 means return 32 bits as is, anything else means return 0 through (Range-1) inclusive.
Returns
A random number in the specified range.

◆ random_seed()

void BURGER_API Burger::RandomBase::random_seed ( void )
noexcept

Seed with a random value.


Init the random number generator with an "Anything goes" policy so programs will power up in an unknown state. Do NOT use this if you wish your title to have recordable demos.

This function will start with the current time as a seed and then it will use a formula that assumes that the tick timer runs at a constant time base but the machine in question does not. As a result, the number of times get() is called is anyone's guess.

See also
set_seed(uint32_t) or get(void).

◆ set_seed()

Burger::RandomBase::set_seed ( uint32_t uNewSeed)
pure virtualnoexcept

Seed the random number generator.


Set the random number generator to a specific seed. This allows altering the random number flow in a controlled manner.

Parameters
uNewSeed32 bit seed value.
See also
get(void) or get_seed(void) const

Implemented in Burger::Random, and Burger::RandomMersenneTwist.

Member Data Documentation

◆ g_StaticRTTI

const Burger::StaticRTTI Burger::RandomBase::g_StaticRTTI
static

The global description of the class.


This record contains the name of this class and a reference to the parent

◆ m_uSeed

uint32_t Burger::RandomBase::m_uSeed
protected

Random number seed.