Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Burger::RandomMersenneTwist Class Reference

Random number generator using Mersenne Twist (MT19937) More...

Inheritance diagram for Burger::RandomMersenneTwist:
Collaboration diagram for Burger::RandomMersenneTwist:

Public Member Functions

const Burger::StaticRTTIget_StaticRTTI (void) const noexcept override
 Get the description to the class.
 
 RandomMersenneTwist (uint32_t uNewSeed=5489U) noexcept
 Static constructor.
 
void set_seed (uint32_t uNewSeed) noexcept override
 Seed the random number generator.
 
uint32_t get (void) noexcept override
 Return a 32 bit pseudo random number.
 
- Public Member Functions inherited from Burger::RandomBase
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 char * get_class_name (void) const noexcept
 Get the name of the class.
 
virtual ~Base () noexcept=default
 Destructor.
 

Static Public Member Functions

static RandomMersenneTwistNew (uint32_t uNewSeed=0) noexcept
 Create a new instance of RandomMersenneTwist.
 

Static Public Attributes

static const Burger::StaticRTTI g_StaticRTTI
 The global description of the class.
 
- Static Public Attributes inherited from Burger::RandomBase
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_Array [kElements]
 Array of seed values (Polynomial)
 
uint32_t m_uIndex
 First lookup index.
 
- Protected Attributes inherited from Burger::RandomBase
uint32_t m_uSeed
 Random number seed.
 

Static Protected Attributes

static const uint_t kElements = 624
 Number of elements in the polynomial array.
 
static const uint_t kTapIndex = 397
 Tap index into the polynomial array.
 

Detailed Description

Random number generator using Mersenne Twist (MT19937)


This class will create random numbers that are spread evenly across a 32 bit range.

https://en.wikipedia.org/wiki/Mersenne_Twister

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

Constructor & Destructor Documentation

◆ RandomMersenneTwist()

Burger::RandomMersenneTwist::RandomMersenneTwist ( uint32_t uNewSeed = 5489U)
noexcept

Static constructor.


Initialize the random number generator with a call to set_seed(uint32_t).

Parameters
uNewSeedNew seed value
See also
set_seed(uint32_t).

Member Function Documentation

◆ get()

uint32_t Burger::RandomMersenneTwist::get ( void )
overridevirtualnoexcept

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)

Implements Burger::RandomBase.

◆ get_StaticRTTI()

const Burger::StaticRTTI * Burger::RandomMersenneTwist::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::RandomBase.

◆ New()

Burger::RandomMersenneTwist *BURGER_API Burger::RandomMersenneTwist::New ( uint32_t uNewSeed = 0)
staticnoexcept

Create a new instance of RandomMersenneTwist.


Create a new random number generator instance using the Burgerlib memory manager.

Parameters
uNewSeedSeed value for the random number generator
Returns
Pointer to instance, or nullptr if out of memory.
See also
set_seed(uint32_t).

◆ set_seed()

void Burger::RandomMersenneTwist::set_seed ( uint32_t uNewSeed)
overridevirtualnoexcept

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

Implements Burger::RandomBase.

Member Data Documentation

◆ g_StaticRTTI

const Burger::StaticRTTI Burger::RandomMersenneTwist::g_StaticRTTI
static

The global description of the class.


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

◆ kElements

const uint_t Burger::RandomMersenneTwist::kElements = 624
staticprotected

Number of elements in the polynomial array.

◆ kTapIndex

const uint_t Burger::RandomMersenneTwist::kTapIndex = 397
staticprotected

Tap index into the polynomial array.

◆ m_Array

uint32_t Burger::RandomMersenneTwist::m_Array[kElements]
protected

Array of seed values (Polynomial)

◆ m_uIndex

uint32_t Burger::RandomMersenneTwist::m_uIndex
protected

First lookup index.