【Boost】boost库的随机数的例子
来源:互联网 发布:淘宝卖家给买家发短信 编辑:程序博客网 时间:2024/05/17 04:26
[cpp] view plain copy print?
- void test_mt19937()
- {
- // 以时间为种子创建一个随机数发生器
- boost::mt19937 rng(time(0));
- for (int i = 0; i < 100; ++i)
- {
- std::cout << rng() << std::endl;
- }
- }
- void test_rand48()
- {
- boost::rand48 rng;
- for (int i = 0; i < 10; ++i)
- {
- std::cout << rng() * 1.0 / std::numeric_limits<boost::rand48::result_type>::max() << std::endl;
- }
- }
- // uniform_smallint:在小整数域内的均匀分布
- // uniform_int:在整数域上的均匀分布
- // uniform_01:在区间[0,1]上的实数连续均匀分布
- // uniform_real:在区间[min,max]上的实数连续均匀分布
- // bernoulli_distribution:伯努利分布
- // binomial_distribution:二项分布
- // cauchy_distribution:柯西(洛伦兹)分布
- // gamma_distribution:伽马分布
- // poisson_distribution:泊松分布
- // geometric_distribution:几何分布
- // triangle_distribution:三角分布
- // exponential_distribution:指数分布
- // normal_distribution:正态分布
- // lognormal_distribution:对数正态分布
- // uniform_on_sphere:球面均匀分布
- void test_random_distribute()
- {
- boost::mt19937 rng(time(0));
- // 1. uniform_int
- boost::uniform_int<> ui(0, 255);
- for (int i = 0; i < 10; ++i)
- {
- std::cout<< ui(rng) << std::endl;
- }
- // 2. uniform_01
- boost::uniform_01<boost::mt19937&> u01(rng);
- for (int i = 0; i < 10; ++i)
- {
- std::cout<< u01() << std::endl;
- }
- }
0 0
- 【Boost】boost库的随机数的例子
- 【Boost】boost库的随机数的例子
- 【Boost】boost库的随机数的例子
- boost库的随机数的例子
- Boost 随机数库的使用
- boost foreach库的例子
- boost::time_wait的例子
- 【Boost】boost::algorithm的几个简单例子
- Boost-Boost库的编译
- boost库解析json的例子
- boost::random产生随机数的一种方法
- 【Boost】boost::bind四种应用场景的例子
- boost随机数
- 【Boost】boost库中function的用法
- 【Boost】boost库中bind的用法
- 【Boost】boost库asio详解8——几个TCP的简单例子
- 【Boost】boost库asio详解8——TCP的简单例子1
- 【Boost】boost库asio详解9——TCP的简单例子2
- DNS域名解析服务器的搭建
- C++学习(一)
- java序列化和反序列化
- php实现post请求 接收android客户端json数据 存储数据库 并返回json
- ubuntu vim安装
- 【Boost】boost库的随机数的例子
- Spring 依赖注入
- [ATL/WTL]_[初级]_[关于CEdit不识别WM_KEYDOWN的问题]
- 【TRIO-Basic从入门到精通教程五】直线、圆弧插补的指令使用
- HDOJ_Prime Ring Problem
- Android烟花效果(SurfaceView实现)
- 6/14 筑个窝
- WPF实现MDI窗体
- ajax_思维导图简单总结