c++ uniform_int_distribution 类
来源:互联网 发布:邯郸学院网络教学平台 编辑:程序博客网 时间:2024/06/11 22:04
#include <random>
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
std::uniform_int_distribution<> distr(a, b);
std::cout << "lower bound == " << distr.a() << std::endl;
std::cout << "upper bound == " << distr.b() << std::endl;
// generate the distribution as a histogram
std::map<int, int> histogram;
for (int i = 0; i < s; ++i) {
++histogram[distr(gen)];
}
// print results
std::cout << "Distribution for " << s << " samples:" << std::endl;
for (const auto& elem : histogram) {
std::cout << std::setw(5) << elem.first << ' ' << std::string(elem.second, ':') << std::endl;
}
std::cout << std::endl;
}
int main()
{
test(1, 5, 100);
}
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
void test(const int a, const int b, const int s) {
std::uniform_int_distribution<> distr(a, b);
std::cout << "lower bound == " << distr.a() << std::endl;
std::cout << "upper bound == " << distr.b() << std::endl;
// generate the distribution as a histogram
std::map<int, int> histogram;
for (int i = 0; i < s; ++i) {
++histogram[distr(gen)];
}
// print results
std::cout << "Distribution for " << s << " samples:" << std::endl;
for (const auto& elem : histogram) {
std::cout << std::setw(5) << elem.first << ' ' << std::string(elem.second, ':') << std::endl;
}
std::cout << std::endl;
}
int main()
{
test(1, 5, 100);
}
0 0
- c++ uniform_int_distribution 类
- 【c/c++】复数类
- 【c/c++】类模板
- [C/C++] 类
- 【C/C++】嵌套类
- 【C/C++】模板类
- C++------类
- C#--类
- C++-->类
- 【C++】类
- 【C#】类
- c++,C#,java中的类
- c与c++?励志类
- 【C/C++】String类实现
- 【C/C++】类和结构
- 含有指针成员的类的拷贝[C/C++/C#]
- 不能被继承的类[C/C++/C#]
- Objective-C类-Objective-C self 关键字
- Uva11825 - Hackers' Crackdown
- ESP8266学习笔记5:ESP8266接入yeelink
- web服务器并发访问如何提升
- 黑马程序员_面向对象笔记
- codeforces 558E A Simple Task 线段树
- c++ uniform_int_distribution 类
- thinkphp获取数组大小
- java io流常用类的使用
- zynq虐我千百遍——第4篇 Linaro之rootfs
- 杭电1145 so you want to be a 2n-aire?
- universal image loader在listview/gridview中滚动时重复加载图片的问题及解决方法
- java基本控制语句的小例子
- itunes connect开发者账号的区别,企业账号,个人账号,公司团队账号,教育账号
- new challenge