[rand.dist] (original) (raw)

29 Numerics library [numerics]

29.5 Random number generation [rand]

29.5.9 Random number distribution class templates [rand.dist]

29.5.9.1 General [rand.dist.general]

Descriptions are provided in [rand.dist] only for distribution operations that are not described in [rand.req.dist]or for operations where there is additional semantic information.

In particular, declarations for copy constructors, for copy assignment operators, for streaming operators, and for equality and inequality operators are not shown in the synopses.

The algorithms for producing each of the specified distributions areimplementation-defined.

The value of each probability density function p(z)and of each discrete probability function specified in this subclause is 0everywhere outside its stated domain.

29.5.9.2 Uniform distributions [rand.dist.uni]

29.5.9.2.1 Class template uniform_int_distribution [rand.dist.uni.int]

A uniform_int_distribution random number distribution produces random integers i,a ≤ i ≤ b, distributed according to the constant discrete probability function in Formula 29.2.

namespace std { template<class IntType = int> class uniform_int_distribution { public: using result_type = IntType;using param_type = unspecified; uniform_int_distribution() : uniform_int_distribution(0) {} explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max());explicit uniform_int_distribution(const param_type& parm);void reset();friend bool operator==(const uniform_int_distribution& x, const uniform_int_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); result_type a() const; result_type b() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const uniform_int_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, uniform_int_distribution& x);};}

explicit uniform_int_distribution(IntType a, IntType b = numeric_limits<IntType>::max());

Remarks: a and b correspond to the respective parameters of the distribution.

Returns: The value of the a parameter with which the object was constructed.

Returns: The value of the b parameter with which the object was constructed.

29.5.9.2.2 Class template uniform_real_distribution [rand.dist.uni.real]

A uniform_real_distribution random number distribution produces random numbers x,, distributed according to the constant probability density function in Formula 29.3.

[Note 1:

This implies that p(x | a,b) is undefined when a == b.

— _end note_]

namespace std { template<class RealType = double> class uniform_real_distribution { public: using result_type = RealType;using param_type = unspecified; uniform_real_distribution() : uniform_real_distribution(0.0) {} explicit uniform_real_distribution(RealType a, RealType b = 1.0);explicit uniform_real_distribution(const param_type& parm);void reset();friend bool operator==(const uniform_real_distribution& x,const uniform_real_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); result_type a() const; result_type b() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const uniform_real_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, uniform_real_distribution& x);};}

explicit uniform_real_distribution(RealType a, RealType b = 1.0);

Preconditions: a ≤ band.

Remarks: a and b correspond to the respective parameters of the distribution.

Returns: The value of the a parameter with which the object was constructed.

Returns: The value of the b parameter with which the object was constructed.

29.5.9.3 Bernoulli distributions [rand.dist.bern]

29.5.9.3.1 Class bernoulli_distribution [rand.dist.bern.bernoulli]

A bernoulli_distribution random number distribution produces bool values bdistributed according to the discrete probability function in Formula 29.4.

namespace std { class bernoulli_distribution { public: using result_type = bool;using param_type = unspecified; bernoulli_distribution() : bernoulli_distribution(0.5) {} explicit bernoulli_distribution(double p);explicit bernoulli_distribution(const param_type& parm);void reset();friend bool operator==(const bernoulli_distribution& x, const bernoulli_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm);double p() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const bernoulli_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, bernoulli_distribution& x);};}

explicit bernoulli_distribution(double p);

Preconditions: 0 ≤ p ≤ 1.

Remarks: p corresponds to the parameter of the distribution.

Returns: The value of the p parameter with which the object was constructed.

29.5.9.3.2 Class template binomial_distribution [rand.dist.bern.bin]

A binomial_distribution random number distribution produces integer values i ≥ 0distributed according to the discrete probability function in Formula 29.5.

namespace std { template<class IntType = int> class binomial_distribution { public: using result_type = IntType;using param_type = unspecified; binomial_distribution() : binomial_distribution(1) {} explicit binomial_distribution(IntType t, double p = 0.5);explicit binomial_distribution(const param_type& parm);void reset();friend bool operator==(const binomial_distribution& x, const binomial_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); IntType t() const;double p() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const binomial_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, binomial_distribution& x);};}

explicit binomial_distribution(IntType t, double p = 0.5);

Preconditions: 0 ≤ p ≤ 1 and 0 ≤ t.

Remarks: t and p correspond to the respective parameters of the distribution.

Returns: The value of the t parameter with which the object was constructed.

Returns: The value of the p parameter with which the object was constructed.

29.5.9.3.3 Class template geometric_distribution [rand.dist.bern.geo]

A geometric_distribution random number distribution produces integer values i ≥ 0distributed according to the discrete probability function in Formula 29.6.

namespace std { template<class IntType = int> class geometric_distribution { public: using result_type = IntType;using param_type = unspecified; geometric_distribution() : geometric_distribution(0.5) {} explicit geometric_distribution(double p);explicit geometric_distribution(const param_type& parm);void reset();friend bool operator==(const geometric_distribution& x, const geometric_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm);double p() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const geometric_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, geometric_distribution& x);};}

explicit geometric_distribution(double p);

Remarks: p corresponds to the parameter of the distribution.

Returns: The value of the p parameter with which the object was constructed.

29.5.9.3.4 Class template negative_binomial_distribution [rand.dist.bern.negbin]

A negative_binomial_distribution random number distribution produces random integers i ≥ 0distributed according to the discrete probability function in Formula 29.7.

[Note 1:

This implies that P(i | k,p) is undefined when p == 1.

— _end note_]

namespace std { template<class IntType = int> class negative_binomial_distribution { public: using result_type = IntType;using param_type = unspecified; negative_binomial_distribution() : negative_binomial_distribution(1) {} explicit negative_binomial_distribution(IntType k, double p = 0.5);explicit negative_binomial_distribution(const param_type& parm);void reset();friend bool operator==(const negative_binomial_distribution& x,const negative_binomial_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); IntType k() const;double p() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const negative_binomial_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, negative_binomial_distribution& x);};}

explicit negative_binomial_distribution(IntType k, double p = 0.5);

Remarks: k and p correspond to the respective parameters of the distribution.

Returns: The value of the k parameter with which the object was constructed.

Returns: The value of the p parameter with which the object was constructed.

29.5.9.4 Poisson distributions [rand.dist.pois]

29.5.9.4.1 Class template poisson_distribution [rand.dist.pois.poisson]

A poisson_distribution random number distribution produces integer values i ≥ 0distributed according to the discrete probability function in Formula 29.8.

The distribution parameter μis also known as this distribution's mean.

namespace std { template<class IntType = int> class poisson_distribution { public: using result_type = IntType;using param_type = unspecified; poisson_distribution() : poisson_distribution(1.0) {} explicit poisson_distribution(double mean);explicit poisson_distribution(const param_type& parm);void reset();friend bool operator==(const poisson_distribution& x, const poisson_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm);double mean() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const poisson_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, poisson_distribution& x);};}

explicit poisson_distribution(double mean);

Remarks: mean corresponds to the parameter of the distribution.

Returns: The value of the mean parameter with which the object was constructed.

29.5.9.4.2 Class template exponential_distribution [rand.dist.pois.exp]

An exponential_distribution random number distribution produces random numbers distributed according to the probability density function in Formula 29.9.

namespace std { template<class RealType = double> class exponential_distribution { public: using result_type = RealType;using param_type = unspecified; exponential_distribution() : exponential_distribution(1.0) {} explicit exponential_distribution(RealType lambda);explicit exponential_distribution(const param_type& parm);void reset();friend bool operator==(const exponential_distribution& x, const exponential_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); RealType lambda() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const exponential_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, exponential_distribution& x);};}

explicit exponential_distribution(RealType lambda);

Remarks: lambda corresponds to the parameter of the distribution.

Returns: The value of the lambda parameter with which the object was constructed.

29.5.9.4.3 Class template gamma_distribution [rand.dist.pois.gamma]

A gamma_distribution random number distribution produces random numbers distributed according to the probability density function in Formula 29.10.

namespace std { template<class RealType = double> class gamma_distribution { public: using result_type = RealType;using param_type = unspecified; gamma_distribution() : gamma_distribution(1.0) {} explicit gamma_distribution(RealType alpha, RealType beta = 1.0);explicit gamma_distribution(const param_type& parm);void reset();friend bool operator==(const gamma_distribution& x, const gamma_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); RealType alpha() const; RealType beta() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const gamma_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, gamma_distribution& x);};}

explicit gamma_distribution(RealType alpha, RealType beta = 1.0);

Remarks: alpha and betacorrespond to the parameters of the distribution.

Returns: The value of the alpha parameter with which the object was constructed.

Returns: The value of the beta parameter with which the object was constructed.

29.5.9.4.4 Class template weibull_distribution [rand.dist.pois.weibull]

A weibull_distribution random number distribution produces random numbers x ≥ 0distributed according to the probability density function in Formula 29.11.

namespace std { template<class RealType = double> class weibull_distribution { public: using result_type = RealType;using param_type = unspecified; weibull_distribution() : weibull_distribution(1.0) {} explicit weibull_distribution(RealType a, RealType b = 1.0);explicit weibull_distribution(const param_type& parm);void reset();friend bool operator==(const weibull_distribution& x, const weibull_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); RealType a() const; RealType b() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const weibull_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, weibull_distribution& x);};}

explicit weibull_distribution(RealType a, RealType b = 1.0);

Remarks: a and bcorrespond to the respective parameters of the distribution.

Returns: The value of the a parameter with which the object was constructed.

Returns: The value of the b parameter with which the object was constructed.

29.5.9.4.5 Class template extreme_value_distribution [rand.dist.pois.extreme]

An extreme_value_distribution random number distribution produces random numbers xdistributed according to the probability density function in Formula 29.12.247

namespace std { template<class RealType = double> class extreme_value_distribution { public: using result_type = RealType;using param_type = unspecified; extreme_value_distribution() : extreme_value_distribution(0.0) {} explicit extreme_value_distribution(RealType a, RealType b = 1.0);explicit extreme_value_distribution(const param_type& parm);void reset();friend bool operator==(const extreme_value_distribution& x,const extreme_value_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); RealType a() const; RealType b() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const extreme_value_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, extreme_value_distribution& x);};}

explicit extreme_value_distribution(RealType a, RealType b = 1.0);

Remarks: a and bcorrespond to the respective parameters of the distribution.

Returns: The value of the a parameter with which the object was constructed.

Returns: The value of the b parameter with which the object was constructed.

29.5.9.5 Normal distributions [rand.dist.norm]

29.5.9.5.1 Class template normal_distribution [rand.dist.norm.normal]

A normal_distribution random number distribution produces random numbers xdistributed according to the probability density function in Formula 29.13.

The distribution parameters μ and σare also known as this distribution's meanand standard deviation.

namespace std { template<class RealType = double> class normal_distribution { public: using result_type = RealType;using param_type = unspecified; normal_distribution() : normal_distribution(0.0) {} explicit normal_distribution(RealType mean, RealType stddev = 1.0);explicit normal_distribution(const param_type& parm);void reset();friend bool operator==(const normal_distribution& x, const normal_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); RealType mean() const; RealType stddev() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const normal_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, normal_distribution& x);};}

explicit normal_distribution(RealType mean, RealType stddev = 1.0);

Remarks: mean and stddevcorrespond to the respective parameters of the distribution.

Returns: The value of the mean parameter with which the object was constructed.

Returns: The value of the stddev parameter with which the object was constructed.

29.5.9.5.2 Class template lognormal_distribution [rand.dist.norm.lognormal]

A lognormal_distribution random number distribution produces random numbers distributed according to the probability density function in Formula 29.14.

namespace std { template<class RealType = double> class lognormal_distribution { public: using result_type = RealType;using param_type = unspecified; lognormal_distribution() : lognormal_distribution(0.0) {} explicit lognormal_distribution(RealType m, RealType s = 1.0);explicit lognormal_distribution(const param_type& parm);void reset();friend bool operator==(const lognormal_distribution& x, const lognormal_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); RealType m() const; RealType s() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const lognormal_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, lognormal_distribution& x);};}

explicit lognormal_distribution(RealType m, RealType s = 1.0);

Remarks: m and scorrespond to the respective parameters of the distribution.

Returns: The value of the m parameter with which the object was constructed.

Returns: The value of the s parameter with which the object was constructed.

29.5.9.5.3 Class template chi_squared_distribution [rand.dist.norm.chisq]

A chi_squared_distribution random number distribution produces random numbers distributed according to the probability density function in Formula 29.15.

namespace std { template<class RealType = double> class chi_squared_distribution { public: using result_type = RealType;using param_type = unspecified; chi_squared_distribution() : chi_squared_distribution(1.0) {} explicit chi_squared_distribution(RealType n);explicit chi_squared_distribution(const param_type& parm);void reset();friend bool operator==(const chi_squared_distribution& x, const chi_squared_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); RealType n() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const chi_squared_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, chi_squared_distribution& x);};}

explicit chi_squared_distribution(RealType n);

Remarks: n corresponds to the parameter of the distribution.

Returns: The value of the n parameter with which the object was constructed.

29.5.9.5.4 Class template cauchy_distribution [rand.dist.norm.cauchy]

A cauchy_distribution random number distribution produces random numbers xdistributed according to the probability density function in Formula 29.16.

namespace std { template<class RealType = double> class cauchy_distribution { public: using result_type = RealType;using param_type = unspecified; cauchy_distribution() : cauchy_distribution(0.0) {} explicit cauchy_distribution(RealType a, RealType b = 1.0);explicit cauchy_distribution(const param_type& parm);void reset();friend bool operator==(const cauchy_distribution& x, const cauchy_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); RealType a() const; RealType b() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const cauchy_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, cauchy_distribution& x);};}

explicit cauchy_distribution(RealType a, RealType b = 1.0);

Remarks: a and bcorrespond to the respective parameters of the distribution.

Returns: The value of the a parameter with which the object was constructed.

Returns: The value of the b parameter with which the object was constructed.

29.5.9.5.5 Class template fisher_f_distribution [rand.dist.norm.f]

A fisher_f_distribution random number distribution produces random numbers x ≥ 0distributed according to the probability density function in Formula 29.17.

namespace std { template<class RealType = double> class fisher_f_distribution { public: using result_type = RealType;using param_type = unspecified; fisher_f_distribution() : fisher_f_distribution(1.0) {} explicit fisher_f_distribution(RealType m, RealType n = 1.0);explicit fisher_f_distribution(const param_type& parm);void reset();friend bool operator==(const fisher_f_distribution& x, const fisher_f_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); RealType m() const; RealType n() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const fisher_f_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, fisher_f_distribution& x);};}

explicit fisher_f_distribution(RealType m, RealType n = 1);

Remarks: m and ncorrespond to the respective parameters of the distribution.

Returns: The value of the m parameter with which the object was constructed.

Returns: The value of the n parameter with which the object was constructed.

29.5.9.5.6 Class template student_t_distribution [rand.dist.norm.t]

A student_t_distribution random number distribution produces random numbers xdistributed according to the probability density function in Formula 29.18.

namespace std { template<class RealType = double> class student_t_distribution { public: using result_type = RealType;using param_type = unspecified; student_t_distribution() : student_t_distribution(1.0) {} explicit student_t_distribution(RealType n);explicit student_t_distribution(const param_type& parm);void reset();friend bool operator==(const student_t_distribution& x, const student_t_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); RealType n() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const student_t_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, student_t_distribution& x);};}

explicit student_t_distribution(RealType n);

Remarks: n corresponds to the parameter of the distribution.

Returns: The value of the n parameter with which the object was constructed.

29.5.9.6 Sampling distributions [rand.dist.samp]

29.5.9.6.1 Class template discrete_distribution [rand.dist.samp.discrete]

A discrete_distribution random number distribution produces random integers i, , distributed according to the discrete probability function in Formula 29.19.

Unless specified otherwise, the distribution parameters are calculated as: for , in which the values , commonly known as the weights, shall be non-negative, non-NaN, and non-infinity.

Moreover, the following relation shall hold:.

namespace std { template<class IntType = int> class discrete_distribution { public: using result_type = IntType;using param_type = unspecified; discrete_distribution();template<class InputIterator> discrete_distribution(InputIterator firstW, InputIterator lastW); discrete_distribution(initializer_list<double> wl);template<class UnaryOperation> discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);explicit discrete_distribution(const param_type& parm);void reset();friend bool operator==(const discrete_distribution& x, const discrete_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); vector<double> probabilities() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const discrete_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, discrete_distribution& x);};}

Effects: Constructs a discrete_distribution object with and .

[Note 1:

Such an object will always deliver the value 0.

— _end note_]

template<class InputIterator> discrete_distribution(InputIterator firstW, InputIterator lastW);

Mandates: is_convertible_v<iterator_traits<InputIterator>​::​value_type,double> is true.

If firstW == lastW, let and .

Otherwise,[firstW, lastW) forms a sequence w of length .

Effects: Constructs a discrete_distribution object with probabilities given by the Formula 29.19.

discrete_distribution(initializer_list<double> wl);

Effects: Same as discrete_distribution(wl.begin(), wl.end()).

template<class UnaryOperation> discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);

Mandates: is_invocable_r_v<double, UnaryOperation&, double> is true.

Preconditions: If , let , otherwise let .

The relation holds.

Effects: Constructs a discrete_distribution object with probabilities given by the formula above, using the following values: If , let .

Otherwise, let for .

Complexity: The number of invocations of fw does not exceed n.

vector<double> probabilities() const;

Returns: A vector<double> whose size member returns n and whose operator[] member returns when invoked with argument k for .

29.5.9.6.2 Class template piecewise_constant_distribution [rand.dist.samp.pconst]

A piecewise_constant_distribution random number distribution produces random numbers x,, uniformly distributed over each subintervalaccording to the probability density function in Formula 29.20.

The distribution parameters , also known as this distribution's interval boundaries, shall satisfy the relation for .

Unless specified otherwise, the remaining n distribution parameters are calculated as:
in which the values , commonly known as the weights, shall be non-negative, non-NaN, and non-infinity.

Moreover, the following relation shall hold:.

namespace std { template<class RealType = double> class piecewise_constant_distribution { public: using result_type = RealType;using param_type = unspecified; piecewise_constant_distribution();template<class InputIteratorB, class InputIteratorW> piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB, InputIteratorW firstW);template<class UnaryOperation> piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);template<class UnaryOperation> piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);explicit piecewise_constant_distribution(const param_type& parm);void reset();friend bool operator==(const piecewise_constant_distribution& x,const piecewise_constant_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); vector<result_type> intervals() const; vector<result_type> densities() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const piecewise_constant_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, piecewise_constant_distribution& x);};}

piecewise_constant_distribution();

Effects: Constructs a piecewise_constant_distribution object with ,,, and .

template<class InputIteratorB, class InputIteratorW> piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB, InputIteratorW firstW);

Mandates: Both of

are true.

If firstB == lastB or ++firstB == lastB, let ,,, and .

Otherwise,[firstB, lastB) forms a sequence b of length , the length of the sequence w starting from firstW is at least n, and any for k ≥ n are ignored by the distribution.

Effects: Constructs a piecewise_constant_distribution object with parameters as specified above.

template<class UnaryOperation> piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);

Mandates: is_invocable_r_v<double, UnaryOperation&, double> is true.

Effects: Constructs a piecewise_constant_distribution object with parameters taken or calculated from the following values: If , let ,,, and .

Otherwise, let [bl.begin(), bl.end()) form a sequence , and let for .

Complexity: The number of invocations of fw does not exceed n.

template<class UnaryOperation> piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);

Mandates: is_invocable_r_v<double, UnaryOperation&, double> is true.

Preconditions: If , let , otherwise let .

The relation holds.

Effects: Constructs a piecewise_constant_distribution object with parameters taken or calculated from the following values: Let for , and for .

Complexity: The number of invocations of fw does not exceed n.

vector<result_type> intervals() const;

Returns: A vector<result_type> whose size member returns and whose operator[] member returns when invoked with argument k for .

vector<result_type> densities() const;

Returns: A vector<result_type> whose size member returns n and whose operator[] member returns when invoked with argument k for .

29.5.9.6.3 Class template piecewise_linear_distribution [rand.dist.samp.plinear]

A piecewise_linear_distribution random number distribution produces random numbers x,, distributed over each subintervalaccording to the probability density function in Formula 29.21.

The distribution parameters , also known as this distribution's interval boundaries, shall satisfy the relation for .

Unless specified otherwise, the remaining distribution parameters are calculated as for , in which the values , commonly known as the weights at boundaries, shall be non-negative, non-NaN, and non-infinity.

Moreover, the following relation shall hold:

namespace std { template<class RealType = double> class piecewise_linear_distribution { public: using result_type = RealType;using param_type = unspecified; piecewise_linear_distribution();template<class InputIteratorB, class InputIteratorW> piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB, InputIteratorW firstW);template<class UnaryOperation> piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw);template<class UnaryOperation> piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);explicit piecewise_linear_distribution(const param_type& parm);void reset();friend bool operator==(const piecewise_linear_distribution& x,const piecewise_linear_distribution& y);template<class URBG> result_type operator()(URBG& g);template<class URBG> result_type operator()(URBG& g, const param_type& parm); vector<result_type> intervals() const; vector<result_type> densities() const; param_type param() const;void param(const param_type& parm); result_type min() const; result_type max() const;template<class charT, class traits> friend basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const piecewise_linear_distribution& x);template<class charT, class traits> friend basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, piecewise_linear_distribution& x);};}

piecewise_linear_distribution();

Effects: Constructs a piecewise_linear_distribution object with ,,, and .

template<class InputIteratorB, class InputIteratorW> piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB, InputIteratorW firstW);

Mandates: Both of

are true.

If firstB == lastB or ++firstB == lastB, let ,,, and .

Otherwise,[firstB, lastB) forms a sequence b of length , the length of the sequence w starting from firstW is at least , and any for are ignored by the distribution.

Effects: Constructs a piecewise_linear_distribution object with parameters as specified above.

template<class UnaryOperation> piecewise_linear_distribution(initializer_list<RealType> bl, UnaryOperation fw);

Mandates: is_invocable_r_v<double, UnaryOperation&, double> is true.

Effects: Constructs a piecewise_linear_distribution object with parameters taken or calculated from the following values: If , let ,,, and .

Otherwise, let [bl.begin(), bl.end()) form a sequence , and let for .

Complexity: The number of invocations of fw does not exceed .

template<class UnaryOperation> piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);

Mandates: is_invocable_r_v<double, UnaryOperation&, double> is true.

Preconditions: If , let , otherwise let .

The relation holds.

Effects: Constructs a piecewise_linear_distribution object with parameters taken or calculated from the following values: Let for , and for .

Complexity: The number of invocations of fw does not exceed .

vector<result_type> intervals() const;

Returns: A vector<result_type> whose size member returns and whose operator[] member returns when invoked with argument k for .

vector<result_type> densities() const;

Returns: A vector<result_type> whose size member returns n and whose operator[] member returns when invoked with argument k for .