使用Blitz++生成随机数的例子
2009-06-08 17:10
344 查看
下面是用Blitz++生成随机数的例子
#include <ctime> #include <iostream> #include <random/uniform.h> //均匀分布 #include <random/normal.h> //正态分布 #include <random/exponential.h> //指数分布 #include <random/discrete-uniform.h>//离散均匀分布 #include <random/beta.h> //Beta 分布 #include <random/gamma.h>//Gamma 分布 #include <random/chisquare.h>//χ^2 分布 #include <random/F.h> //F分布 using namespace ranlib; using namespace std; int _tmain(int argc, _TCHAR* argv[]) { // 连续均匀随机分布[0,1) Uniform<double> run; run.seed((unsigned int)time(0)); cout<<run.random()<<endl; // 连续均匀随机分布[0,1] UniformClosed<double> run1; run1.seed((unsigned int)time(0)); cout<<run1.random()<<endl; // 连续均匀随机分布(0,1) UniformOpen<double> run2; run2.seed((unsigned int)time(0)); cout<<run2.random()<<endl; // 连续均匀随机分布(0,1] UniformOpenClosed<double> run3; run3.seed((unsigned int)time(0)); cout<<run3.random()<<endl; // 1到99的离散均匀分布的随机数 DiscreteUniform<long> rdu(100); rdu.seed((unsigned int)time(0)); cout<<rdu.random()<<endl; // 正态分布 Normal<double> rnor(10,2); rnor.seed((unsigned int)time(0)); cout<<rnor.random()<<endl; // Beta分布有问题 // Beta<double> rba; // cout<<rba.random()<<endl; // cout<<numeric_limits<double>::min(); // 指数分布 Exponential<double> rex(0.5); cout<<rex.random(); //.. return 0; }
相关文章推荐
- 使用js生成随机数
- jar包的生成和使用简单例子
- 【原创】开源Math.NET基础数学类库使用(14)C#生成安全的随机数
- java使用hashset生成1-20的随机数并不重复并打印
- 使用PHP生成随机数方法详解
- Python random模块(获取随机数)常用方法和使用例子
- (原创)按照一定的格式生成一定数量的随机数的例子
- PHP随机数生成与使用解析
- 使用c语言生成随机数的示例分享
- java中生成流水号的一个例子(使用关系型数据库)
- 一个使用自定义命名空间的Schema文件,xml文件和castor生成的java代码的例子
- 使用Uploadify实现上传图片生成缩略图例子,实时显示进度条
- 使用Random类生成随机数
- 关于使用fso组件生成html的例子
- 使用Python生成随机数
- 使用JAVA生成十个随机数并进行排序
- Python random模块(获取随机数)常用方法和使用例子
- 拿来就用——随机数的使用与生成概率
- 使用c#生成不重复的随机数
- JavaScript 使用random()在一个范围内生成随机数