base::Random Class Reference

Generates random numbers from a per-thread safe. More...

#include <base_random.hh>

Inheritance diagram for base::Random:

base::Threadable

List of all members.

Public Member Functions

 Random (void)
 ~Random ()
void Init (void)
void randomize (uint seed)
void randomize (void)
uint random_ui (void)
uint random_ui (uint range)
fp random_f (void)
fp random_f (fp range)
uint random_ui_true (void)
uint GetSeed (void)
uint fast_random_ui (void)
uint fast_random_ui (uint range)
fp fast_random_f (void)
fp fast_random_f (fp range)

Private Attributes

PerThreadPtr< uint0mSeed
uint mSavedSeed
uint mFastTable [FAST_TABLE_CNT+100]
uint mFastTableIdx

Static Private Attributes

static const uint FAST_TABLE_CNT = 1024
static const uint FAST_TABLE_IDX_MASK = 1023


Detailed Description

Generates random numbers from a per-thread safe.

Every thread can set its own seed which is stored in a thread variable.


Constructor & Destructor Documentation

base::Random::Random ( void   ) 

ctor/dtor.

base::Random::~Random (  ) 


Member Function Documentation

void base::Random::Init ( void   ) 

Initialize random number generator.

void base::Random::randomize ( uint  seed  ) 

Seed the sequence of psuedo-random numbers.

void base::Random::randomize ( void   ) 

uint base::Random::random_ui ( void   ) 

Returns:
A psuedo-random unsigned int in range {0,..,RAND_MAX}.

uint base::Random::random_ui ( uint  end  ) 

Returns:
A psuedo-random unsigned int in range {0,..,end-1}. end-1 is for picking a random-but-valid index within a container by passing size of container as end. random_ui(100) will return {0,..,99} (never 100).

fp base::Random::random_f ( void   ) 

Returns:
A psuedo-random float in range {0,..,1} or {0,..,range}.

fp base::Random::random_f ( fp  range  ) 

uint base::Random::random_ui_true ( void   ) 

Returns:
A true random unsigned integer.
Remarks:
This function is slow. An alternative is to call randomize( random_true() ) once and thereafter call the pseudo-random functions.

uint base::Random::GetSeed ( void   )  [inline]

uint base::Random::fast_random_ui ( void   )  [inline]

uint base::Random::fast_random_ui ( uint  range  )  [inline]

fp base::Random::fast_random_f ( void   )  [inline]

fp base::Random::fast_random_f ( fp  range  )  [inline]


Member Data Documentation

const uint base::Random::FAST_TABLE_CNT = 1024 [static, private]

const uint base::Random::FAST_TABLE_IDX_MASK = 1023 [static, private]

PerThreadPtr<uint0> base::Random::mSeed [private]

uint base::Random::mSavedSeed [private]

uint base::Random::mFastTable[FAST_TABLE_CNT+100] [private]

uint base::Random::mFastTableIdx [private]


The documentation for this class was generated from the following files: Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:19 2007