OpenBarnyard
 
Loading...
Searching...
No Matches
TRandom Class Reference

#include <TRandom.h>

Public Member Functions

 TRandom ()
 
TINT GetInt ()
 
TINT GetInt (TUINT32 a_iLower, TUINT32 a_iUpper)
 
TINT GetInt (TUINT32 a_iUpper)
 
TFLOAT GetFloat ()
 
TFLOAT GetFloatMinMax (TFLOAT a_fLower, TFLOAT a_fUpper)
 
TFLOAT GetFloat2 ()
 
TUINT32 RandRaw ()
 
void SetSeed (TUINT a_uiSeed)
 
TUINT32 GetSeed () const
 

Detailed Description

Definition at line 21 of file TRandom.h.

Constructor & Destructor Documentation

◆ TRandom()

TRandom::TRandom ( )

Definition at line 59 of file TRandom.cpp.

60{
61 THPTimer timer = THPTimer();
62 SetSeed( timer.GetRaw32() );
63}
void SetSeed(TUINT a_uiSeed)
Definition TRandom.cpp:199
TUINT32 GetRaw32()

Member Function Documentation

◆ GetFloat()

TFLOAT TRandom::GetFloat ( )

Definition at line 183 of file TRandom.cpp.

184{
185 return ( RandRaw() >> 1 ) * 4.6566129E-10f;
186}
TUINT32 RandRaw()
Definition TRandom.cpp:205

◆ GetFloat2()

TFLOAT TRandom::GetFloat2 ( )

Definition at line 194 of file TRandom.cpp.

195{
196 return ( RandRaw() >> 1 ) * 9.3132257E-10f * -1.0f;
197}

◆ GetFloatMinMax()

TFLOAT TRandom::GetFloatMinMax ( TFLOAT a_fLower,
TFLOAT a_fUpper )

Definition at line 189 of file TRandom.cpp.

190{
191 return (TFLOAT)( RandRaw() >> 1 ) * 4.6566129E-10f * ( a_fUpper - a_fLower ) + a_fLower;
192}
float TFLOAT
Definition Typedefs.h:4

◆ GetInt() [1/3]

TINT TRandom::GetInt ( )

Definition at line 178 of file TRandom.cpp.

179{
180 return RandRaw();
181}

◆ GetInt() [2/3]

TINT TRandom::GetInt ( TUINT32 a_iLower,
TUINT32 a_iUpper )

Definition at line 163 of file TRandom.cpp.

164{
165 TASSERT( a_iUpper > a_iLower, "a_iLower can't be higher than a_iUpper" );
166
167 unsigned long long rand = RandRaw();
168 unsigned long long range = a_iUpper - a_iLower;
169 return a_iLower + ( range * rand >> 32 );
170}
#define TASSERT(X,...)
Definition Defines.h:138

◆ GetInt() [3/3]

TINT TRandom::GetInt ( TUINT32 a_iUpper)

Definition at line 173 of file TRandom.cpp.

174{
175 return GetInt( 0, a_iUpper );
176}
TINT GetInt()
Definition TRandom.cpp:178

◆ GetSeed()

TUINT32 TRandom::GetSeed ( ) const
inline

Definition at line 37 of file TRandom.h.

37{ return m_uiSeed; }

◆ RandRaw()

TUINT32 TRandom::RandRaw ( )

Definition at line 205 of file TRandom.cpp.

206{
207 if ( ( m_uiRndCnt-- ) != 0 )
208 {
209 return m_pRandrsl[ m_uiRndCnt ];
210 }
211
212 Isaac();
213 m_uiRndCnt = RANDSIZ - 1;
214 return m_pRandrsl[ RANDSIZ - 1 ];
215}
#define RANDSIZ
Definition TRandom.h:15

◆ SetSeed()

void TRandom::SetSeed ( TUINT a_uiSeed)

Definition at line 199 of file TRandom.cpp.

200{
201 m_uiSeed = a_uiSeed;
202 RandInit();
203}

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