Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cRandomBase Class Referenceabstract

#include <cRandom.h>

Inheritance diagram for Gray::cRandomBase:
Gray::IRandomNoise Gray::cRandomDef Gray::cRandomOS GrayLib::cRandomFloat GrayLib::cRandomBGenerator GrayLib::cRandomCombo2< _TYPE1, _TYPE2 > GrayLib::cRandomFloatDef GrayLib::cRandomMersenne GrayLib::cRandomWGenerator

Public Types

typedef UINT SEED_t
 default seed size might be 32 or 64 bit depending on k_RAND_MAX. More...
 

Public Member Functions

 cRandomBase () noexcept
 
virtual ~cRandomBase ()
 
virtual void InitSeed (const void *pData, size_t iSize)=0
 
void InitSeed (IRandomNoise *pSrc, size_t iSize)
 the default random number generator. NOT Thread Safe! More...
 
void InitSeedDefault (size_t iSize=sizeof(int))
 
void InitSeedUns (UINT iSeed)
 
virtual HRESULT GetNoise (void *pData, size_t iSize) override
 fill array with random. return # filled. More...
 
virtual UINT get_RandUns ()
 
bool GetRandBool ()
 
virtual UINT GetRandUX (UINT nScale)
 
int GetRandIRange (int iRangeLo, int iRangeHi)
 

Friends

class cRandomTests
 

Detailed Description

Generic abstract base class for a integer/binary (pseudo) random number generator. Similar to .NET System.Random

Note
derived class MUST implement get_RandUns or GetRandUX to generate at least 32 bits or 31 bits of random data.

Member Typedef Documentation

◆ SEED_t

default seed size might be 32 or 64 bit depending on k_RAND_MAX.

Constructor & Destructor Documentation

◆ cRandomBase()

Gray::cRandomBase::cRandomBase ( )
inlinenoexcept

◆ ~cRandomBase()

virtual Gray::cRandomBase::~cRandomBase ( )
inlinevirtual

Member Function Documentation

◆ get_RandUns()

UINT Gray::cRandomBase::get_RandUns ( )
virtual

get UINT random number in 0 to < UINT_MAX range default implementation.

Note
derived implementation MUST override get_RandUns or GetRandUX

Reimplemented in GrayLib::cRandomWGenerator, GrayLib::cRandomBGenerator, GrayLib::cRandomMersenne, and Gray::cRandomOS.

◆ GetNoise()

HRESULT Gray::cRandomBase::GetNoise ( void *  pData,
size_t  iSize 
)
overridevirtual

fill array with random. return # filled.

fill a buffer with random bytes of data. < 0 = error.

Implements Gray::IRandomNoise.

Reimplemented in Gray::cRandomOS.

◆ GetRandBool()

bool Gray::cRandomBase::GetRandBool ( )
inline

flip a coin.

◆ GetRandIRange()

int Gray::cRandomBase::GetRandIRange ( int  iRangeLo,
int  iRangeHi 
)

get a random integer inclusive inside range. default implementation.

Returns
a random number in an inclusive range of integers.

◆ GetRandUX()

UINT Gray::cRandomBase::GetRandUX ( UINT  nScale)
virtual

Get random number in scale. 0 to scale. unsigned integer is NON inclusive range. from 0 to nScale-1

get random integer number in 0 to < nScale range NON inclusive default implementation.

Note
derived implementation MUST override get_RandUns() or GetRandUX()

Reimplemented in GrayLib::cRandomFloatDef, GrayLib::cRandomCombo2< _TYPE1, _TYPE2 >, and Gray::cRandomDef.

◆ InitSeed() [1/2]

virtual void Gray::cRandomBase::InitSeed ( const void *  pData,
size_t  iSize 
)
pure virtual

◆ InitSeed() [2/2]

void Gray::cRandomBase::InitSeed ( IRandomNoise pSrc,
size_t  iSize 
)

the default random number generator. NOT Thread Safe!

◆ InitSeedDefault()

void Gray::cRandomBase::InitSeedDefault ( size_t  iSize = sizeof(int))

Initialize random sequence randomly. Seed the random generator with time or some mix of more random data. NOT Deterministic!

◆ InitSeedUns()

void Gray::cRandomBase::InitSeedUns ( UINT  iSeed)

set seed from UINT. Similar to SEED_t

Friends And Related Function Documentation

◆ cRandomTests

friend class cRandomTests
friend

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