/****************************************************************************************


	MCRandom.h

	Copyright: (c) 2001 Eovia Corp. All rights reserved.

	Author:		Ray Dream 
	Date:		3/2/98

	Revision History

  	when		who			what & why
	==========	==========	======================================================
	7/21/99		cph			Fixed bug in RealRand()
	10/16/98	Nba			Added Rand for real32
	10/07/98	Nba			Added MCRandomStep, TMCRandom
	3/5/98		Greg		Initial conversion

*****************************************************************************************/

#ifndef __MCRANDOM__
#define __MCRANDOM__

#include "MCBasicTypes.h"
#include "MCBasicDefines.h"


int32	MCRandomStep	(int32 before);
int32	MCRandomSteps	(int32 before, int32 steps);
int32 	MCRandom		();
void 	MCSetRandomSeed	(int32 seed);
void	MCCleanRandom	();

/// \addtogroup MCCore
/// \{

/// Random Number Generator
///
class TMCRandom
{
	int32 fSeed;
public:
	TMCRandom			() : fSeed(0)		 {}
	TMCRandom			(int32 seed)
	{
		SetSeed(seed);
	}

	void  SetSeed		(int32 seed) {fSeed = seed;}
	int32 GetSeed		() const	 { return fSeed; }
	int32 Rand			()
	{
		fSeed = MCRandomStep(fSeed);
		return fSeed;
	}
	int32 RandRange(int32 min, int32 max)
	{
		fSeed = MCRandomStep(fSeed);
		return ((max - min) * ((int16)(fSeed & 0x7fff)) >> 15) + min;
	}
	real32 RealRand		()
	{ 
		return real32(uint32(Rand())) / (real32) kUINT32_MAX;	// there must be somthing better than that
	}

	/// Returns a nicely distributed random number between 0 and 1.
	///
	real FloatAbs()
	{
		int32 intValue = (Rand() & 0x7fffff);
		return real(intValue) / 0x7fffff;
	}

	void Advance(int32 steps) { fSeed = MCRandomSteps(fSeed, steps); }
};
/// \}

#endif