資源簡介
代碼中提供了指定分布的c++實現,分別是正態分布,帕累托分布,對數正態分布,均勻分布

代碼片段和文件信息
//?random.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“Random.h“
#include?
#include?
#include?
#define?PI?3.14151926
int?main(int?argc?char*?argv[])
{
return?0;
}
//////////////////////////////////////////////////////////////////////
//?CRandom?Class
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRandom::CRandom()
{
}
CRandom::~CRandom()
{
}
double?CRandom::ExponentialDistribution(double?lamda)
{
double?rdn=0;
srand((unsigned)time(NULL));
do?
{
rdn?=?rand()?/?RAND_MAX;
}?while?(rdn?==?0?||?rdn?==?1);
return?(-1.0?/?lamda?)?*?log(1?-?rdn);
}
double?CRandom::LogNormDistribution(double?meandouble?stddev)
{
double?rdn1=0;
double?rdn2=0;
srand((unsigned)time(NULL));
do?
{
rdn1?=?rand()?/?RAND_MAX;
rdn2?=?rand()?/?RAND_MAX;
}?while?(rdn1?==?0?||?rdn1?==?1?||?rdn2?==?0?||?rdn2?==?1);
double?stdNorm?=?sqrt(-2?*?log(rdn2))?*?cos(2?*?PI?*?rdn1);
return?exp(stddev?*?stdNorm?+?mean);
}
double?CRandom::UniformDistribution(double?min?double?max)
{
double?diffValue?=?max?-?min;
double?rdn=0;
srand((unsigned)time(NULL));
do?
{
rdn?=?rand()?/?RAND_MAX;
}?while?(rdn?==?0?||?rdn?==?1);
return?rdn?*?diffValue?+?min;
}
double?CRandom::ParetoDistribution(double?minX?double?alpha)
{
double?rdn=0;
srand((unsigned)time(NULL));
do?
{
rdn?=?rand()?/?RAND_MAX;
}?while?(rdn?==?0?||?rdn?==?1);
return?minX?*?exp(?(-1.0?/?alpha)?*?log(1-rdn)?);
}
//DEL?double?CRandom::a(int?int)
//DEL?{
//DEL?
//DEL?}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????50176??2011-07-16?14:12??random\Debug\random.bsc
?????文件?????221236??2011-07-16?14:12??random\Debug\random.exe
?????文件?????228376??2011-07-16?14:12??random\Debug\random.ilk
?????文件???????8239??2011-07-16?14:12??random\Debug\random.obj
?????文件?????191020??2011-07-16?14:12??random\Debug\random.pch
?????文件?????402432??2011-07-16?14:12??random\Debug\random.pdb
?????文件??????????0??2011-07-16?14:12??random\Debug\random.sbr
?????文件???????1923??2011-07-16?14:12??random\Debug\StdAfx.obj
?????文件????????158??2011-07-16?14:12??random\Debug\StdAfx.sbr
?????文件??????41984??2011-07-16?22:40??random\Debug\vc60.idb
?????文件??????53248??2011-07-16?14:12??random\Debug\vc60.pdb
?????文件???????1806??2011-07-16?22:40??random\random.cpp
?????文件???????4601??2011-07-17?00:12??random\random.dsp
?????文件????????537??2011-07-17?00:12??random\random.dsw
?????文件????????710??2011-07-16?14:11??random\Random.h
?????文件??????33792??2011-07-17?00:12??random\random.ncb
?????文件??????49664??2011-07-17?00:12??random\random.opt
?????文件???????1873??2011-07-16?14:12??random\random.plg
?????文件???????1208??2011-07-16?10:43??random\ReadMe.txt
?????文件????????293??2011-07-16?10:43??random\StdAfx.cpp
?????文件????????667??2011-07-16?10:43??random\StdAfx.h
?????目錄??????????0??2011-07-16?14:12??random\Debug
?????目錄??????????0??2011-07-17?00:12??random
-----------?---------??----------?-----??----
??????????????1293943????????????????????23
評論
共有 條評論