tRandomizer Class Reference

Random generator. More...

#include <tRandom.h>

Inheritance diagram for tRandomizer:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 tRandomizer ()
 default constructor
virtual ~tRandomizer ()
 destructor
REAL Get ()
 returns a random float in the interval [0,1)
int Get (int max)
 returns a random integer in the interval [0,max)

Static Public Member Functions

static tRandomizerGetInstance ()
 returns the standard randomizer

Protected Attributes

unsigned int randMax_

Private Member Functions

 tRandomizer (tRandomizer const &other)
 copy constructor
tRandomizeroperator= (tRandomizer const &other)
 copy operator
virtual unsigned int GetRawRand ()
 returns a raw random number


Detailed Description

Random generator.

Definition at line 39 of file tRandom.h.


Constructor & Destructor Documentation

tRandomizer::tRandomizer ( void   ) 

default constructor

Definition at line 53 of file tRandom.cpp.

00054         :randMax_( RAND_MAX )
00055 {
00056 }

tRandomizer::~tRandomizer ( void   )  [virtual]

destructor

Definition at line 122 of file tRandom.cpp.

00123 {
00124 }

tRandomizer::tRandomizer ( tRandomizer const &  other  )  [private]

copy constructor

Parameters:
other copy source

Definition at line 136 of file tRandom.cpp.

References tASSERT.

00137 {
00138     tASSERT( 0 ); // not implemented
00139 }


Member Function Documentation

REAL tRandomizer::Get ( void   ) 

returns a random float in the interval [0,1)

Returns:
random value between 0 and 1

Definition at line 68 of file tRandom.cpp.

References a, b, GetRawRand(), randMax_, and REAL.

Referenced by gCycleChatBot::Activate(), ePlayer::ePlayer(), gGame::GameLoop(), Get(), nServerInfo::GetRandomMaster(), gArena::GetRandomPos(), gSpark::gSpark(), init_exp(), zSelector::pickOne(), nServerInfo::QueryServer(), Random(), nKrawall::RandomSalt(), nSocket::Read(), eAudioPos::Reset(), gGame::StateUpdate(), ve_math_random(), and nSocket::Write().

00069 {
00070     // Grr. VisualC 6 can't handle this in one line.
00071     REAL a = GetRawRand();
00072     REAL b = randMax_;
00073 
00074     return a / b;
00075 }

Here is the call graph for this function:

Here is the caller graph for this function:

int tRandomizer::Get ( int  max  ) 

returns a random integer in the interval [0,max)

Parameters:
max upper limit of the return value
Returns:
random integer value between 0 and max - 1

Definition at line 88 of file tRandom.cpp.

References floorf(), Get(), and tASSERT.

00089 {
00090     int ret = int( floorf( Get() * max ) );
00091     tASSERT( 0 <= ret );
00092     tASSERT( ret < max );
00093 
00094     return ret;
00095 }

Here is the call graph for this function:

tRandomizer & tRandomizer::GetInstance ( void   )  [static]

returns the standard randomizer

Returns:

Reimplemented in tReproducibleRandomizer.

Definition at line 107 of file tRandom.cpp.

Referenced by ePlayer::ePlayer(), gGame::GameLoop(), gSpark::gSpark(), init_exp(), zSelector::pickOne(), Random(), nKrawall::RandomSalt(), eAudioPos::Reset(), gGame::StateUpdate(), and ve_math_random().

00108 {
00109     static tRandomizer randomizer;
00110     return randomizer;
00111 }

Here is the caller graph for this function:

tRandomizer & tRandomizer::operator= ( tRandomizer const &  other  )  [private]

copy operator

Parameters:
other copy source
Returns:
reference to this for chaining

Definition at line 152 of file tRandom.cpp.

References tASSERT.

00153 {
00154     tASSERT( 0 ); // not implemented
00155 
00156     return *this;
00157 }

unsigned int tRandomizer::GetRawRand ( void   )  [private, virtual]

returns a raw random number

Returns:
random value between 0 and randMax_

Reimplemented in tReproducibleRandomizer.

Definition at line 169 of file tRandom.cpp.

Referenced by Get().

00170 {
00171     return rand();
00172 }

Here is the caller graph for this function:


Member Data Documentation

unsigned int tRandomizer::randMax_ [protected]

Definition at line 51 of file tRandom.h.

Referenced by Get(), and tReproducibleRandomizer::tReproducibleRandomizer().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:58:26 2008 for Armagetron Advanced by  doxygen 1.5.4