在线文档教程
C++
数字 | Numerics

std::piecewise_constant_distribution

STD:分段[医]常量[医]分布

Defined in header
template< class RealType = double > class piecewise_constant_distribution;(since C++11)

std::piecewise_constant_distribution产生随机浮点数,这些数字在几个子区间中的每个子区间内均匀分布。[乙

一,乙

I+1%29,每个都有自己的重量w

一、区间边界集合和权值集是这种分布的参数。任何b的概率密度。

I≤x<b

I+1是

wk

*。

S%28 bi+1-bi%29

,其中S是所有权重之和。

std::piecewise_constant_distribution满足…的所有要求RandomNumberDistribution...

模板参数

RealType-The result type generated by the generator. The effect is undefined if this is not one of float, double, or long double.

成员类型

Member typeDefinition
result_typeRealType
param_typethe type of the parameter set, see RandomNumberDistribution.

成员函数

(constructor)constructs new distribution (public member function)
resetresets the internal state of the distribution (public member function)

世代

运算符%28%29在分布%28公共成员函数%29中生成下一个随机数。

特征

中间值密度返回分布参数%28公共成员函数%29

Param获取或设置分布参数对象%28公共成员函数%29

min返回最小潜在生成值%28公共成员函数%29

MAX返回最大潜在生成值%28公共成员函数%29

非会员职能

operator==operator!=compares two distribution objects (function)
operator<<operator>>performs stream input and output on pseudo-random number distribution (function template)

二次

#include <iostream> #include <string> #include <map> #include <random> int main() { std::random_device rd; std::mt19937 gen(rd() // 50% of the time, generate a random number between 0 and 1 // 50% of the time, generate a random number between 10 and 15 std::vector<double> i{0, 1, 10, 15}; std::vector<double> w{ 1, 0, 1}; std::piecewise_constant_distribution<> d(i.begin(), i.end(), w.begin() std::map<int, int> hist; for(int n=0; n<10000; ++n) { ++hist[d(gen)]; } for(auto p : hist) { std::cout << p.first << ' ' << std::string(p.second/100, '*') << '\n'; } }

二次

产出:

二次

0 ************************************************** 10 ********** 11 ********* 12 ********* 13 ********** 14 *********

二次

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/数值/随机/分段[医]常量[医]分布