Files
2025-10-25 03:02:53 +03:00

71 KiB
Raw Permalink Blame History

[rand.dist]

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]

1

#

Each type instantiated from a class template specified in [rand.dist] meets the requirements of a random number distribution type.

2

#

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.

3

#

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

4

#

The value of each probability density function p(z) and of each discrete probability function P(zi) specified in this subclause is 0 everywhere 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]

1

#

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.

P(i|a,b)=1/(b−a+1)(29.2)

🔗

namespace std {templateclass uniform_int_distribution {public:// typesusing result_type = IntType; using param_type = unspecified; // constructors and reset functions uniform_int_distribution() : uniform_int_distribution(0) {}explicit uniform_int_distribution(IntType a, IntType b = numeric_limits::max()); explicit uniform_int_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const uniform_int_distribution& x, const uniform_int_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions 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; // inserters and extractorstemplate<class charT, class traits>friend basic_ostream<charT, traits>&operator<<(basic_ostream<charT, traits>& os, // hostedconst uniform_int_distribution& x); template<class charT, class traits>friend basic_istream<charT, traits>&operator>>(basic_istream<charT, traits>& is, // hosted uniform_int_distribution& x); };}

🔗

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

2

#

Preconditions: a ≤ b.

3

#

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

🔗

result_type a() const;

4

#

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

🔗

result_type b() const;

5

#

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]

1

#

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

p(x|a,b)=1/(b−a)(29.3)

[Note 1:

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

— end note]

🔗

namespace std {templateclass uniform_real_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructors and reset functions 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(); // equality operatorsfriend bool operator==(const uniform_real_distribution& x, const uniform_real_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions 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; // inserters and extractorstemplate<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);

2

#

Preconditions: a ≤ b andb−‰¤numeric_limits::max().

3

#

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

🔗

result_type a() const;

4

#

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

🔗

result_type b() const;

5

#

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]

1

#

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

P(b|p)={p if b=true1−p if b=false(29.4)

🔗

namespace std {class bernoulli_distribution {public:// typesusing result_type = bool; using param_type = unspecified; // constructors and reset functions bernoulli_distribution() : bernoulli_distribution(0.5) {}explicit bernoulli_distribution(double p); explicit bernoulli_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const bernoulli_distribution& x, const bernoulli_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functionsdouble p() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0 ≤ p ≤ 1.

3

#

Remarks: p corresponds to the parameter of the distribution.

🔗

double p() const;

4

#

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]

1

#

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

P(i|t,p)=(ti)â‹piâ‹(1−p)t−i(29.5)

🔗

namespace std {templateclass binomial_distribution {public:// typesusing result_type = IntType; using param_type = unspecified; // constructors and reset functions binomial_distribution() : binomial_distribution(1) {}explicit binomial_distribution(IntType t, double p = 0.5); explicit binomial_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const binomial_distribution& x, const binomial_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions IntType t() const; double p() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

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

3

#

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

🔗

IntType t() const;

4

#

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

🔗

double p() const;

5

#

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]

1

#

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

P(i|p)=pâ‹(1−p)i(29.6)

🔗

namespace std {templateclass geometric_distribution {public:// typesusing result_type = IntType; using param_type = unspecified; // constructors and reset functions geometric_distribution() : geometric_distribution(0.5) {}explicit geometric_distribution(double p); explicit geometric_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const geometric_distribution& x, const geometric_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functionsdouble p() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<p<1.

3

#

Remarks: p corresponds to the parameter of the distribution.

🔗

double p() const;

4

#

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]

1

#

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

P(i|k,p)=(k+i−1i)â‹pkâ‹(1−p)i(29.7)

[Note 1:

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

— end note]

🔗

namespace std {templateclass negative_binomial_distribution {public:// typesusing result_type = IntType; using param_type = unspecified; // constructor and reset functions 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(); // equality operatorsfriend bool operator==(const negative_binomial_distribution& x, const negative_binomial_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions IntType k() const; double p() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<p≤1 and 0<k.

3

#

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

🔗

IntType k() const;

4

#

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

🔗

double p() const;

5

#

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]

1

#

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

P(i|μ)=e−μμii!(29.8)

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

🔗

namespace std {templateclass poisson_distribution {public:// typesusing result_type = IntType; using param_type = unspecified; // constructors and reset functions poisson_distribution() : poisson_distribution(1.0) {}explicit poisson_distribution(double mean); explicit poisson_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const poisson_distribution& x, const poisson_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functionsdouble mean() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<mean.

3

#

Remarks: mean corresponds to the parameter of the distribution.

🔗

double mean() const;

4

#

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]

1

#

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

p(x|λ)=λe−λx(29.9)

🔗

namespace std {templateclass exponential_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructors and reset functions exponential_distribution() : exponential_distribution(1.0) {}explicit exponential_distribution(RealType lambda); explicit exponential_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const exponential_distribution& x, const exponential_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions RealType lambda() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<lambda.

3

#

Remarks: lambda corresponds to the parameter of the distribution.

🔗

RealType lambda() const;

4

#

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]

1

#

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

p(x|α,β)=e−x/ββαâ‹Î“(α)â‹xα−1(29.10)

🔗

namespace std {templateclass gamma_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructors and reset functions gamma_distribution() : gamma_distribution(1.0) {}explicit gamma_distribution(RealType alpha, RealType beta = 1.0); explicit gamma_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const gamma_distribution& x, const gamma_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions RealType alpha() const; RealType beta() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<alpha and 0<beta.

3

#

Remarks: alpha and beta correspond to the parameters of the distribution.

🔗

RealType alpha() const;

4

#

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

🔗

RealType beta() const;

5

#

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]

1

#

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

p(x|a,b)=abâ‹(xb)a−‹exp(−(xb)a)(29.11)

🔗

namespace std {templateclass weibull_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructor and reset functions weibull_distribution() : weibull_distribution(1.0) {}explicit weibull_distribution(RealType a, RealType b = 1.0); explicit weibull_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const weibull_distribution& x, const weibull_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const; RealType b() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<a and 0<b.

3

#

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

🔗

RealType a() const;

4

#

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

🔗

RealType b() const;

5

#

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]

1

#

An extreme_value_distribution random number distribution produces random numbers x distributed according to the probability density function in Formula 29.12.246

p(x|a,b)=1bâ‹exp(a−xb−exp(a−xb))(29.12)

🔗

namespace std {templateclass extreme_value_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructor and reset functions 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(); // equality operatorsfriend bool operator==(const extreme_value_distribution& x, const extreme_value_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const; RealType b() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<b.

3

#

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

🔗

RealType a() const;

4

#

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

🔗

RealType b() const;

5

#

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

246)246)

The distribution corresponding to this probability density function is also known (with a possible change of variable) as the Gumbel Type I, the log-Weibull, or the Fisher-Tippett Type I distribution.

29.5.9.5 Normal distributions [rand.dist.norm]

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

1

#

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

p(x|μ,σ)=1σ√€â‹exp(−(x−μ)22σ2)(29.13)

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

🔗

namespace std {templateclass normal_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructors and reset functions normal_distribution() : normal_distribution(0.0) {}explicit normal_distribution(RealType mean, RealType stddev = 1.0); explicit normal_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const normal_distribution& x, const normal_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions RealType mean() const; RealType stddev() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<stddev.

3

#

Remarks: mean and stddev correspond to the respective parameters of the distribution.

🔗

RealType mean() const;

4

#

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

🔗

RealType stddev() const;

5

#

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]

1

#

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

p(x|m,s)=1sx√€â‹exp(−(lnx−m)22s2)(29.14)

🔗

namespace std {templateclass lognormal_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructor and reset functions lognormal_distribution() : lognormal_distribution(0.0) {}explicit lognormal_distribution(RealType m, RealType s = 1.0); explicit lognormal_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const lognormal_distribution& x, const lognormal_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions RealType m() const; RealType s() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<s.

3

#

Remarks: m and s correspond to the respective parameters of the distribution.

🔗

RealType m() const;

4

#

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

🔗

RealType s() const;

5

#

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]

1

#

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

p(x|n)=x(n/2)−‹ˆ’x/2Γ(n/2)â‹2n/2(29.15)

🔗

namespace std {templateclass chi_squared_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructor and reset functions chi_squared_distribution() : chi_squared_distribution(1.0) {}explicit chi_squared_distribution(RealType n); explicit chi_squared_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const chi_squared_distribution& x, const chi_squared_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions RealType n() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<n.

3

#

Remarks: n corresponds to the parameter of the distribution.

🔗

RealType n() const;

4

#

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]

1

#

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

p(x|a,b)=(πb(1+(x−ab)2))−1(29.16)

🔗

namespace std {templateclass cauchy_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructor and reset functions cauchy_distribution() : cauchy_distribution(0.0) {}explicit cauchy_distribution(RealType a, RealType b = 1.0); explicit cauchy_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const cauchy_distribution& x, const cauchy_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions RealType a() const; RealType b() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<b.

3

#

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

🔗

RealType a() const;

4

#

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

🔗

RealType b() const;

5

#

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]

1

#

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

p(x|m,n)=Γ((m+n)/2)Γ(m/2)Γ(n/2)â‹(mn)m/2â‹x(m/2)−‹(1+mxn)−(m+n)/2(29.17)

🔗

namespace std {templateclass fisher_f_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructor and reset functions 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(); // equality operatorsfriend bool operator==(const fisher_f_distribution& x, const fisher_f_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions RealType m() const; RealType n() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<m and 0<n.

3

#

Remarks: m and n correspond to the respective parameters of the distribution.

🔗

RealType m() const;

4

#

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

🔗

RealType n() const;

5

#

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]

1

#

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

p(x|n)=1√€â‹Î“((n+1)/2)Γ(n/2)â‹(1+x2n)−(n+1)/2(29.18)

🔗

namespace std {templateclass student_t_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructor and reset functions student_t_distribution() : student_t_distribution(1.0) {}explicit student_t_distribution(RealType n); explicit student_t_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const student_t_distribution& x, const student_t_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions RealType n() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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);

2

#

Preconditions: 0<n.

3

#

Remarks: n corresponds to the parameter of the distribution.

🔗

RealType n() const;

4

#

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]

1

#

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

P(i|p0,…,pn−1)=pi(29.19)

2

#

Unless specified otherwise, the distribution parameters are calculated as:pk=wk/S for k=0,…,n−1, in which the values wk, commonly known as the weights, shall be non-negative, non-NaN, and non-infinity.

Moreover, the following relation shall hold:0<S=w0+⋯+wn−1.

🔗

namespace std {templateclass discrete_distribution {public:// typesusing result_type = IntType; using param_type = unspecified; // constructor and reset functions discrete_distribution(); template discrete_distribution(InputIterator firstW, InputIterator lastW); discrete_distribution(initializer_list wl); template discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw); explicit discrete_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const discrete_distribution& x, const discrete_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions vector probabilities() const; param_type param() const; void param(const param_type& parm); result_type min() const; result_type max() const; // inserters and extractorstemplate<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); };}

🔗

discrete_distribution();

3

#

Effects: Constructs a discrete_distribution object with n=1 and p0=1.

[Note 1:

Such an object will always deliver the value 0.

— end note]

🔗

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

4

#

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

5

#

Preconditions: InputIterator meets the Cpp17InputIterator requirements ([input.iterators]).

If firstW == lastW, let n=1 and w0=1.

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

6

#

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

🔗

discrete_distribution(initializer_list<double> wl);

7

#

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

🔗

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

8

#

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

9

#

Preconditions: If nw=0, let n=1, otherwise let n=nw.

The relation 0<δ=(xmax−xmin)/n holds.

10

#

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

Otherwise, let wk=fw(xmin+kâ‹Î´+δ/2) for k=0,…,n−1.

11

#

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

🔗

vector<double> probabilities() const;

12

#

Returns: A vector whose size member returns n and whose operator[] member returns pk when invoked with argument k for k=0,…,n−1.

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

1

#

A piecewise_constant_distribution random number distribution produces random numbers x,b0≤x<bn, uniformly distributed over each subinterval[bi,bi+1) according to the probability density function in Formula 29.20.

p(x|b0,…,bn,ρ0,…,ρˆ’1)=ρi , for bi≤x<bi+1(29.20)

2

#

The n+1 distribution parameters bi, also known as this distribution's interval boundaries, shall satisfy the relationbi<bi+1 for i=0,…,n−1.

Unless specified otherwise, the remaining n distribution parameters are calculated as:
ρk=wkSâ‹(bk+1−bk) for k=0,…,n−1 , in which the values wk, commonly known as the weights, shall be non-negative, non-NaN, and non-infinity.

Moreover, the following relation shall hold: 0<S=w0+⋯+wn−1.

🔗

namespace std {templateclass piecewise_constant_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructor and reset functions piecewise_constant_distribution(); template<class InputIteratorB, class InputIteratorW> piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB, InputIteratorW firstW); template piecewise_constant_distribution(initializer_list bl, UnaryOperation fw); template piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw); explicit piecewise_constant_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const piecewise_constant_distribution& x, const piecewise_constant_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions 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; // inserters and extractorstemplate<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();

3

#

Effects: Constructs a piecewise_constant_distribution object with n=1, ρ0=1, b0=0, and b1=1.

🔗

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

4

#

Mandates: Both of

is_convertible_v<iterator_traits::value_type, double>

is_convertible_v<iterator_traits::value_type, double>

are true.

5

#

Preconditions: InputIteratorB and InputIteratorW each meet the Cpp17InputIterator requirements ([input.iterators]).

If firstB == lastB or ++firstB == lastB, let n=1, w0=1, b0=0, and b1=1.

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

6

#

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

🔗

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

7

#

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

8

#

Effects: Constructs a piecewise_constant_distribution object with parameters taken or calculated from the following values: If bl.size()<2, let n=1, w0=1, b0=0, and b1=1.

Otherwise, let [bl.begin(), bl.end()) form a sequence b0,…,bn, and let wk=fw((bk+1+bk)/2) for k=0,…,n−1.

9

#

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);

10

#

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

11

#

Preconditions: If nw=0, let n=1, otherwise let n=nw.

The relation 0<δ=(xmax−xmin)/n holds.

12

#

Effects: Constructs a piecewise_constant_distribution object with parameters taken or calculated from the following values: Let bk=xmin+kâ‹Î´ for k=0,…,n, and wk=fw(bk+δ/2) for k=0,…,n−1.

13

#

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

🔗

vector<result_type> intervals() const;

14

#

Returns: A vector<result_type> whose size member returns n+1 and whose operator[] member returns bk when invoked with argument k for k=0,…,n.

🔗

vector<result_type> densities() const;

15

#

Returns: A vector<result_type> whose size member returns n and whose operator[] member returns ρk when invoked with argument k for k=0,…,n−1.

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

1

#

A piecewise_linear_distribution random number distribution produces random numbers x,b0≤x<bn, distributed over each subinterval[bi,bi+1) according to the probability density function in Formula 29.21.

p(x|b0,…,bn,ρ0,…,ρn)=ρ‹bi+1−xbi+1−bi+ρi+1⋈’bibi+1−bi , for bi≤x<bi+1.(29.21)

2

#

The n+1 distribution parameters bi, also known as this distribution's interval boundaries, shall satisfy the relation bi<bi+1 for i=0,…,n−1.

Unless specified otherwise, the remaining n+1 distribution parameters are calculated asρk=wk/S for k=0,…,n, in which the values wk, commonly known as the weights at boundaries, shall be non-negative, non-NaN, and non-infinity.

Moreover, the following relation shall hold:
0<S=12⋈’ˆ‘k=0(wk+wk+1)â‹(bk+1−bk) .

🔗

namespace std {templateclass piecewise_linear_distribution {public:// typesusing result_type = RealType; using param_type = unspecified; // constructor and reset functions piecewise_linear_distribution(); template<class InputIteratorB, class InputIteratorW> piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB, InputIteratorW firstW); template piecewise_linear_distribution(initializer_list bl, UnaryOperation fw); template piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw); explicit piecewise_linear_distribution(const param_type& parm); void reset(); // equality operatorsfriend bool operator==(const piecewise_linear_distribution& x, const piecewise_linear_distribution& y); // generating functionstemplate result_type operator()(URBG& g); template result_type operator()(URBG& g, const param_type& parm); // property functions 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; // inserters and extractorstemplate<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();

3

#

Effects: Constructs a piecewise_linear_distribution object with n=1, ρ0=ρ1=1, b0=0, and b1=1.

🔗

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

4

#

Mandates: Both of

is_convertible_v<iterator_traits::value_type, double>

is_convertible_v<iterator_traits::value_type, double>

are true.

5

#

Preconditions: InputIteratorB and InputIteratorW each meet the Cpp17InputIterator requirements ([input.iterators]).

If firstB == lastB or ++firstB == lastB, let n=1, ρ0=ρ1=1, b0=0, and b1=1.

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

6

#

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

🔗

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

7

#

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

8

#

Effects: Constructs a piecewise_linear_distribution object with parameters taken or calculated from the following values: If bl.size()<2, let n=1, ρ0=ρ1=1, b0=0, and b1=1.

Otherwise, let [bl.begin(), bl.end()) form a sequence b0,…,bn, and let wk=fw(bk) for k=0,…,n.

9

#

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

🔗

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

10

#

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

11

#

Preconditions: If nw=0, let n=1, otherwise let n=nw.

The relation 0<δ=(xmax−xmin)/n holds.

12

#

Effects: Constructs a piecewise_linear_distribution object with parameters taken or calculated from the following values: Let bk=xmin+kâ‹Î´ for k=0,…,n, and wk=fw(bk) for k=0,…,n.

13

#

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

🔗

vector<result_type> intervals() const;

14

#

Returns: A vector<result_type> whose size member returns n+1 and whose operator[] member returns bk when invoked with argument k for k=0,…,n.

🔗

vector<result_type> densities() const;

15

#

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