std::discre...distribution(3)
hey bestie π welcome to std::discrete_distribution::discrete_distribution β the constructor page from the C++ Standard Libary manual (yes, that spelling is the manual name, not me typoing, periodt π). You might see it squished in the header as std::discre...distribution(3), but the actual star of the show is the std::discrete_distribution constructor. It's lowkey giving βmake a distribution objectβ energy, and honestly? highkey iconic. This page ate and left no crumbs, fr fr. π§β¨
πΈ NAME πΈ
std::discrete_distribution::discrete_distribution β std::discrete_distribution::discrete_distribution. That's literally the constructor page, bestie. No cap. π
π¦ Synopsis π¦
Vibe check: all five are (since C++11) and they're serving:
discrete_distribution();
(1) (since C++11)
template< class InputIt >
discrete_distribution( InputIt first, InputIt last );
(2) (since C++11)
discrete_distribution( std::initializer_list<double> weights );
(3) (since C++11)
template< class UnaryOperation >
discrete_distribution( std::size_t count, double xmin, double xmax,
UnaryOperation unary_op );
(4) (since C++11)
explicit discrete_distribution( const param_type& params );
(5) (since C++11)
Constructs a new distribution object. π«Ά
Here's the tea on each overload:
- Default constructor. Constructs the distribution with a single weight
p = {1}. This distribution will always generate0. (ngl, one-trick pony but reliable, honestly π ) - Constructs the distribution with weights in the range
[first, last). Iffirst == last, the effects are the same as of the default constructor. - Constructs the distribution with weights in
weights. Effectively callsdiscrete_distribution(weights.begin(), weights.end()). - Constructs the distribution with
countweights that are generated using functionunary_op. Each of the weights is equal tow_i = unary_op(xmin + Ξ΄(i + 0.5)), whereΞ΄ = (xmax β xmin) / countβ yes, math, but make it cute π β andi β {0, ..., count β 1}.xminandxmaxmust be such thatΞ΄ > 0. Ifcount == 0, the effects are the same as of the default constructor. - Constructs the distribution with
paramsas the distribution parameters.
π Parameters π
first,lastβ the range of elements defining the numbers to use as weights. The type of the elements referred byInputIteratormust be convertible todouble.weightsβ initializer list containing the weights.unary_opβ unary operation function object that will be applied. The signature of the function should be equivalent to the following:
Ret fun(const Type &a);
The signature does not need to have const &. The type Type must be such that an object of type double can be dereferenced and then implicitly converted to Type. The type Ret must be such that an object of type double can be dereferenced and assigned a value of type Ret.
paramsβ the distribution parameter set.
π Type requirements π
InputItmust meet the requirements ofLegacyInputIterator.
okay that's the whole page, bestie π«Ά source/version is http://cppreference.com, dated 2024.06.10. Go forth and construct something iconic, slay. π
β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms