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

#include <cRandom.h>

Inheritance diagram for Gray::cRandomDef:
Gray::cRandomBase Gray::IRandomNoise

Public Member Functions

 cRandomDef (SEED_t nSeed=1)
 
virtual ~cRandomDef ()
 
SEED_t GetRandNext ()
 
virtual void InitSeed (const void *pData, size_t iSize) override
 
virtual UINT GetRandUX (UINT nScale) override
 
- Public Member Functions inherited from Gray::cRandomBase
 cRandomBase () noexcept
 
virtual ~cRandomBase ()
 
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 ()
 
int GetRandIRange (int iRangeLo, int iRangeHi)
 

Static Public Attributes

static const SEED_t k_RAND_MAX = 0x7fff
 0x7fff = RAND_MAX, 31 bits of random. More...
 

Additional Inherited Members

- Public Types inherited from Gray::cRandomBase
typedef UINT SEED_t
 default seed size might be 32 or 64 bit depending on k_RAND_MAX. More...
 

Detailed Description

Like the default 'C' library seeded pseudo-random number generator ::srand() and ::rand() Control a series of pseudo random numbers via a seed. not thread safe. Use cThreadLocal to make thread safe. RESOLUTION = k_RAND_MAX

Constructor & Destructor Documentation

◆ cRandomDef()

Gray::cRandomDef::cRandomDef ( SEED_t  nSeed = 1)

◆ ~cRandomDef()

Gray::cRandomDef::~cRandomDef ( )
virtual

Member Function Documentation

◆ GetRandNext()

UINT Gray::cRandomDef::GetRandNext ( )

Get next pseudo random number like ::rand(); k_RAND_MAX assumed to be 32767

◆ GetRandUX()

UINT Gray::cRandomDef::GetRandUX ( UINT  nScale)
overridevirtual

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

Returns
value from 0 to less than nScale. (non inclusive of nScale) granularity may be effected by k_RAND_MAX (much larger for Linux) like rand()
Note
: _WIN32 rand() is NOT thread safe. 2 threads will get the same value if called at the same time !!

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

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

Reimplemented from Gray::cRandomBase.

◆ InitSeed()

void Gray::cRandomDef::InitSeed ( const void *  pData,
size_t  iSize 
)
overridevirtual

Start a repeatable series of pseudo random numbers like ::srand()

Implements Gray::cRandomBase.

Member Data Documentation

◆ k_RAND_MAX

const SEED_t Gray::cRandomDef::k_RAND_MAX = 0x7fff
static

0x7fff = RAND_MAX, 31 bits of random.


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