diff options
| author | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:31:46 -0800 |
|---|---|---|
| committer | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:46:31 -0800 |
| commit | f56bb35301836e56582a575a75864392a0177875 (patch) | |
| tree | de61ddd39de3e7df52759711950b4c288592f0dc /sp/src/public/vstdlib/random.h | |
| parent | Mark some more files as text. (diff) | |
| download | source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.tar.xz source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.zip | |
Fix line endings. WHAMMY.
Diffstat (limited to 'sp/src/public/vstdlib/random.h')
| -rw-r--r-- | sp/src/public/vstdlib/random.h | 222 |
1 files changed, 111 insertions, 111 deletions
diff --git a/sp/src/public/vstdlib/random.h b/sp/src/public/vstdlib/random.h index 5c56eb12..88188031 100644 --- a/sp/src/public/vstdlib/random.h +++ b/sp/src/public/vstdlib/random.h @@ -1,111 +1,111 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose: Random number generator
-//
-// $Workfile: $
-// $NoKeywords: $
-//===========================================================================//
-
-#ifndef VSTDLIB_RANDOM_H
-#define VSTDLIB_RANDOM_H
-
-#include "vstdlib/vstdlib.h"
-#include "tier0/basetypes.h"
-#include "tier0/threadtools.h"
-#include "tier1/interface.h"
-
-#define NTAB 32
-
-#pragma warning(push)
-#pragma warning( disable:4251 )
-
-//-----------------------------------------------------------------------------
-// A generator of uniformly distributed random numbers
-//-----------------------------------------------------------------------------
-class IUniformRandomStream
-{
-public:
- // Sets the seed of the random number generator
- virtual void SetSeed( int iSeed ) = 0;
-
- // Generates random numbers
- virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f ) = 0;
- virtual int RandomInt( int iMinVal, int iMaxVal ) = 0;
- virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f ) = 0;
-};
-
-
-//-----------------------------------------------------------------------------
-// The standard generator of uniformly distributed random numbers
-//-----------------------------------------------------------------------------
-class VSTDLIB_CLASS CUniformRandomStream : public IUniformRandomStream
-{
-public:
- CUniformRandomStream();
-
- // Sets the seed of the random number generator
- virtual void SetSeed( int iSeed );
-
- // Generates random numbers
- virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f );
- virtual int RandomInt( int iMinVal, int iMaxVal );
- virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f );
-
-private:
- int GenerateRandomNumber();
-
- int m_idum;
- int m_iy;
- int m_iv[NTAB];
-
- CThreadFastMutex m_mutex;
-};
-
-
-//-----------------------------------------------------------------------------
-// A generator of gaussian distributed random numbers
-//-----------------------------------------------------------------------------
-class VSTDLIB_CLASS CGaussianRandomStream
-{
-public:
- // Passing in NULL will cause the gaussian stream to use the
- // installed global random number generator
- CGaussianRandomStream( IUniformRandomStream *pUniformStream = NULL );
-
- // Attaches to a random uniform stream
- void AttachToStream( IUniformRandomStream *pUniformStream = NULL );
-
- // Generates random numbers
- float RandomFloat( float flMean = 0.0f, float flStdDev = 1.0f );
-
-private:
- IUniformRandomStream *m_pUniformStream;
- bool m_bHaveValue;
- float m_flRandomValue;
-
- CThreadFastMutex m_mutex;
-};
-
-
-//-----------------------------------------------------------------------------
-// A couple of convenience functions to access the library's global uniform stream
-//-----------------------------------------------------------------------------
-VSTDLIB_INTERFACE void RandomSeed( int iSeed );
-VSTDLIB_INTERFACE float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f );
-VSTDLIB_INTERFACE float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f );
-VSTDLIB_INTERFACE int RandomInt( int iMinVal, int iMaxVal );
-VSTDLIB_INTERFACE float RandomGaussianFloat( float flMean = 0.0f, float flStdDev = 1.0f );
-
-
-//-----------------------------------------------------------------------------
-// Installs a global random number generator, which will affect the Random functions above
-//-----------------------------------------------------------------------------
-VSTDLIB_INTERFACE void InstallUniformRandomStream( IUniformRandomStream *pStream );
-
-
-#pragma warning(pop)
-
-#endif // VSTDLIB_RANDOM_H
-
-
-
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Random number generator +// +// $Workfile: $ +// $NoKeywords: $ +//===========================================================================// + +#ifndef VSTDLIB_RANDOM_H +#define VSTDLIB_RANDOM_H + +#include "vstdlib/vstdlib.h" +#include "tier0/basetypes.h" +#include "tier0/threadtools.h" +#include "tier1/interface.h" + +#define NTAB 32 + +#pragma warning(push) +#pragma warning( disable:4251 ) + +//----------------------------------------------------------------------------- +// A generator of uniformly distributed random numbers +//----------------------------------------------------------------------------- +class IUniformRandomStream +{ +public: + // Sets the seed of the random number generator + virtual void SetSeed( int iSeed ) = 0; + + // Generates random numbers + virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f ) = 0; + virtual int RandomInt( int iMinVal, int iMaxVal ) = 0; + virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f ) = 0; +}; + + +//----------------------------------------------------------------------------- +// The standard generator of uniformly distributed random numbers +//----------------------------------------------------------------------------- +class VSTDLIB_CLASS CUniformRandomStream : public IUniformRandomStream +{ +public: + CUniformRandomStream(); + + // Sets the seed of the random number generator + virtual void SetSeed( int iSeed ); + + // Generates random numbers + virtual float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f ); + virtual int RandomInt( int iMinVal, int iMaxVal ); + virtual float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f ); + +private: + int GenerateRandomNumber(); + + int m_idum; + int m_iy; + int m_iv[NTAB]; + + CThreadFastMutex m_mutex; +}; + + +//----------------------------------------------------------------------------- +// A generator of gaussian distributed random numbers +//----------------------------------------------------------------------------- +class VSTDLIB_CLASS CGaussianRandomStream +{ +public: + // Passing in NULL will cause the gaussian stream to use the + // installed global random number generator + CGaussianRandomStream( IUniformRandomStream *pUniformStream = NULL ); + + // Attaches to a random uniform stream + void AttachToStream( IUniformRandomStream *pUniformStream = NULL ); + + // Generates random numbers + float RandomFloat( float flMean = 0.0f, float flStdDev = 1.0f ); + +private: + IUniformRandomStream *m_pUniformStream; + bool m_bHaveValue; + float m_flRandomValue; + + CThreadFastMutex m_mutex; +}; + + +//----------------------------------------------------------------------------- +// A couple of convenience functions to access the library's global uniform stream +//----------------------------------------------------------------------------- +VSTDLIB_INTERFACE void RandomSeed( int iSeed ); +VSTDLIB_INTERFACE float RandomFloat( float flMinVal = 0.0f, float flMaxVal = 1.0f ); +VSTDLIB_INTERFACE float RandomFloatExp( float flMinVal = 0.0f, float flMaxVal = 1.0f, float flExponent = 1.0f ); +VSTDLIB_INTERFACE int RandomInt( int iMinVal, int iMaxVal ); +VSTDLIB_INTERFACE float RandomGaussianFloat( float flMean = 0.0f, float flStdDev = 1.0f ); + + +//----------------------------------------------------------------------------- +// Installs a global random number generator, which will affect the Random functions above +//----------------------------------------------------------------------------- +VSTDLIB_INTERFACE void InstallUniformRandomStream( IUniformRandomStream *pStream ); + + +#pragma warning(pop) + +#endif // VSTDLIB_RANDOM_H + + + |