www.pudn.com > Grass.rar > Rand.h


// Rand.h: interface for the CRand class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#if !defined(AFX_RAND_H__93D96587_C99E_4DD1_BB23_6B6C3BB68C28__INCLUDED_) 
#define AFX_RAND_H__93D96587_C99E_4DD1_BB23_6B6C3BB68C28__INCLUDED_ 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
 
#include "BaseTypes.h" 
 
void _srand(unsigned long iseed); 
RandType _rand(void); 
RandType _randgauss(void); 
RandType _randBiExponential(void); 
RandType _randExponential(void); 
RandType _randBiUniform(void); 
 
class CRandBase 
{ 
public: 
	CRandBase(RandType new_mean=0,RandType new_stdev=1) 
		:m_mean(new_mean),m_seed(1010101) 
	{ 
		m_stdev=new_stdev>0?new_stdev:-new_stdev; 
	}; 
	void setseed(long new_seed); 
	void setCurSeed(long new_seed); 
	void setCurSeed(); 
	void setmean(RandType new_mean){ m_mean=new_mean;}; 
	void setdev(RandType new_stdev) 
	{  
		m_stdev=new_stdev>0?new_stdev:-new_stdev; 
	}; 
	RandType getmean(void){ return m_mean;}; 
	RandType getdev(void){ return m_stdev;}; 
	virtual RandType next(void)=0; 
	virtual ~CRandBase(){}; 
protected: 
	RandType m_mean,m_stdev; 
	long m_seed; 
}; 
 
class CRandUniform : public CRandBase 
{ 
public: 
	CRandUniform(RandType new_mean=0,RandType new_stdev=1) 
		:CRandBase(new_mean,new_stdev) 
	{ 
	}; 
	virtual ~CRandUniform(){}; 
	virtual RandType next(void); 
}; 
 
class CRandExponential : public CRandBase 
{ 
public: 
	CRandExponential(RandType new_mean=0,RandType new_stdev=1) 
		:CRandBase(new_mean,new_stdev) 
	{ 
		CalcRange(); 
	}; 
	virtual ~CRandExponential(){}; 
	virtual RandType next(void); 
	void CalcRange(); 
private: 
	RandType m_min,m_max; 
}; 
 
class CRandGauss : public CRandBase 
{ 
public: 
	CRandGauss(RandType new_mean=0,RandType new_stdev=1) 
		:CRandBase(new_mean,new_stdev) 
	{ 
	}; 
	virtual ~CRandGauss(){}; 
	virtual RandType next(void); 
}; 
 
#endif // !defined(AFX_RAND_H__93D96587_C99E_4DD1_BB23_6B6C3BB68C28__INCLUDED_)