# 26 Numerics library [numerics]

## 26.5 Random number generation [rand]

### 26.5.8 Random number distribution class templates [rand.dist]

#### 26.5.8.1 In general [rand.dist.general]

Each type instantiated from a class template specified in this section [rand.dist] satisfies the requirements of a random number distribution ([rand.req.dist]) type.

Descriptions are provided in this section [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 are implementation-defined.

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

#### 26.5.8.2.1 Class template uniform_int_distribution[rand.dist.uni.int]

A uniform_int_distribution random number distribution produces random integers i, aib , distributed according to the constant discrete probability function P(i | a,b) = 1 / (b - a + 1) .

template<class IntType = int>
class uniform_int_distribution{
public:
// types
typedef IntType result_type;
typedef unspecified param_type;

// constructors and reset functions
explicit uniform_int_distribution(IntType a = 0, IntType b = numeric_limits<IntType>::max());
explicit uniform_int_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


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

Requires: ab .

Effects: Constructs a uniform_int_distribution object; a and b correspond to the respective parameters of the distribution.

 result_type a() const; 

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

 result_type b() const; 

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

#### 26.5.8.2.2 Class template uniform_real_distribution[rand.dist.uni.real]

A uniform_real_distribution random number distribution produces random numbers x, ax < b , distributed according to the constant probability density function p(x | a,b) = 1 / (b - a) .

template<class RealType = double>
class uniform_real_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructors and reset functions
explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
explicit uniform_real_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


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

Requires: ab and b - anumeric_limits<RealType>::max() .

Effects: Constructs a uniform_real_distribution object; a and b correspond to the respective parameters of the distribution.

 result_type a() const; 

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

 result_type b() const; 

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

#### 26.5.8.3.1 Class bernoulli_distribution[rand.dist.bern.bernoulli]

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

class bernoulli_distribution{
public:
// types
typedef bool result_type;
typedef unspecified param_type;

// constructors and reset functions
explicit bernoulli_distribution(double p = 0.5);
explicit bernoulli_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& g, const param_type& parm);

// property functions
double p() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
};


 explicit bernoulli_distribution(double p = 0.5); 

Requires: 0 ≤ p ≤ 1.

Effects: Constructs a bernoulli_distribution object; p corresponds to the parameter of the distribution.

 double p() const; 

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

#### 26.5.8.3.2 Class template binomial_distribution[rand.dist.bern.bin]

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

template<class IntType = int>
class binomial_distribution{
public:
// types
typedef IntType result_type;
typedef unspecified param_type;

// constructors and reset functions
explicit binomial_distribution(IntType t = 1, double p = 0.5);
explicit binomial_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


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

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

Effects: Constructs a binomial_distribution object; t and p correspond to the respective parameters of the distribution.

 IntType t() const; 

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

 double p() const; 

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

#### 26.5.8.3.3 Class template geometric_distribution[rand.dist.bern.geo]

A geometric_distribution random number distribution produces integer values i ≥ 0 distributed according to the discrete probability function P(i | p) = p · (1-p)i .

template<class IntType = int>
class geometric_distribution{
public:
// types
typedef IntType result_type;
typedef unspecified param_type;

// constructors and reset functions
explicit geometric_distribution(double p = 0.5);
explicit geometric_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& g, const param_type& parm);

// property functions
double p() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
};


 explicit geometric_distribution(double p = 0.5); 

Requires: 0 < p < 1.

Effects: Constructs a geometric_distribution object; p corresponds to the parameter of the distribution.

 double p() const; 

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

#### 26.5.8.3.4 Class template negative_binomial_distribution[rand.dist.bern.negbin]

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

template<class IntType = int>
class negative_binomial_distribution{
public:
// types
typedef IntType  result_type;
typedef unspecified param_type;

// constructor and reset functions
explicit negative_binomial_distribution(IntType k = 1, double p = 0.5);
explicit negative_binomial_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


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

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

Effects: Constructs a negative_binomial_distribution object; k and p correspond to the respective parameters of the distribution.

 IntType k() const; 

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

 double p() const; 

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

#### 26.5.8.4.1 Class template poisson_distribution[rand.dist.pois.poisson]

A poisson_distribution random number distribution produces integer values i ≥ 0 distributed according to the discrete probability function The distribution parameter μ is also known as this distribution's mean.

template<class IntType = int>
class poisson_distribution{
public:
// types
typedef IntType result_type;
typedef unspecified param_type;

// constructors and reset functions
explicit poisson_distribution(double mean = 1.0);
explicit poisson_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& g, const param_type& parm);

// property functions
double mean() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
};


 explicit poisson_distribution(double mean = 1.0); 

Requires: 0 < mean .

Effects: Constructs a poisson_distribution object; mean corresponds to the parameter of the distribution.

 double mean() const; 

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

#### 26.5.8.4.2 Class template exponential_distribution[rand.dist.pois.exp]

An exponential_distribution random number distribution produces random numbers x > 0 distributed according to the probability density function p(x | λ) = λ ex .

template<class RealType = double>
class exponential_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructors and reset functions
explicit exponential_distribution(RealType lambda = 1.0);
explicit exponential_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


 explicit exponential_distribution(RealType lambda = 1.0); 

Requires: 0 < lambda .

Effects: Constructs a exponential_distribution object; lambda corresponds to the parameter of the distribution.

 RealType lambda() const; 

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

#### 26.5.8.4.3 Class template gamma_distribution[rand.dist.pois.gamma]

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

template<class RealType = double>
class gamma_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructors and reset functions
explicit gamma_distribution(RealType alpha = 1.0, RealType beta = 1.0);
explicit gamma_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


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

Requires: 0 < alpha and 0 < beta .

Effects: Constructs a gamma_distribution object; alpha and beta correspond to the parameters of the distribution.

 RealType alpha() const; 

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

 RealType beta() const; 

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

#### 26.5.8.4.4 Class template weibull_distribution[rand.dist.pois.weibull]

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

template<class RealType = double>
class weibull_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructor and reset functions
explicit weibull_distribution(RealType a = 1.0, RealType b = 1.0);
explicit weibull_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


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

Requires: 0 < a and 0 < b .

Effects: Constructs a weibull_distribution object; a and b correspond to the respective parameters of the distribution.

 RealType a() const; 

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

 RealType b() const; 

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

#### 26.5.8.4.5 Class template extreme_value_distribution[rand.dist.pois.extreme]

An extreme_value_distribution random number distribution produces random numbers x distributed according to the probability density function280

template<class RealType = double>
class extreme_value_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructor and reset functions
explicit extreme_value_distribution(RealType a = 0.0, RealType b = 1.0);
explicit extreme_value_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


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

Requires: 0 < b .

Effects: Constructs an extreme_value_distribution object; a and b correspond to the respective parameters of the distribution.

 RealType a() const; 

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

 RealType b() const; 

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

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.

#### 26.5.8.5.1 Class template normal_distribution[rand.dist.norm.normal]

A normal_distribution random number distribution produces random numbers x distributed according to the probability density function The distribution parameters μ and σ are also known as this distribution's mean and standard deviation.

template<class RealType = double>
class normal_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructors and reset functions
explicit normal_distribution(RealType mean = 0.0, RealType stddev = 1.0);
explicit normal_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


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

Requires: 0 < stddev .

Effects: Constructs a normal_distribution object; mean and stddev correspond to the respective parameters of the distribution.

 RealType mean() const; 

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

 RealType stddev() const; 

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

#### 26.5.8.5.2 Class template lognormal_distribution[rand.dist.norm.lognormal]

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

template<class RealType = double>
class lognormal_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructor and reset functions
explicit lognormal_distribution(RealType m = 0.0, RealType s = 1.0);
explicit lognormal_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


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

Requires: 0 < s .

Effects: Constructs a lognormal_distribution object; m and s correspond to the respective parameters of the distribution.

 RealType m() const; 

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

 RealType s() const; 

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

#### 26.5.8.5.3 Class template chi_squared_distribution[rand.dist.norm.chisq]

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

template<class RealType = double>
class chi_squared_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructor and reset functions
explicit chi_squared_distribution(RealType n = 1);
explicit chi_squared_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


 explicit chi_squared_distribution(RealType n = 1); 

Requires: 0 < n .

Effects: Constructs a chi_squared_distribution object; n corresponds to the parameter of the distribution.

 RealType n() const; 

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

#### 26.5.8.5.4 Class template cauchy_distribution[rand.dist.norm.cauchy]

A cauchy_distribution random number distribution produces random numbers x distributed according to the probability density function

template<class RealType = double>
class cauchy_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructor and reset functions
explicit cauchy_distribution(RealType a = 0.0, RealType b = 1.0);
explicit cauchy_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


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

Requires: 0 < b .

Effects: Constructs a cauchy_distribution object; a and b correspond to the respective parameters of the distribution.

 RealType a() const; 

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

 RealType b() const; 

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

#### 26.5.8.5.5 Class template fisher_f_distribution[rand.dist.norm.f]

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

template<class RealType = double>
class fisher_f_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructor and reset functions
explicit fisher_f_distribution(RealType m = 1, RealType n = 1);
explicit fisher_f_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


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

Requires: 0 < m and 0 < n .

Effects: Constructs a fisher_f_distribution object; m and n correspond to the respective parameters of the distribution.

 RealType m() const; 

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

 RealType n() const; 

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

#### 26.5.8.5.6 Class template student_t_distribution[rand.dist.norm.t]

A student_t_distribution random number distribution produces random numbers x distributed according to the probability density function

template<class RealType = double>
class student_t_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructor and reset functions
explicit student_t_distribution(RealType n = 1);
explicit student_t_distribution(const param_type& parm);
void reset();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


 explicit student_t_distribution(RealType n = 1); 

Requires: 0 < n .

Effects: Constructs a student_t_distribution object; n corresponds to the parameter of the distribution.

 RealType n() const; 

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

#### 26.5.8.6.1 Class template discrete_distribution[rand.dist.samp.discrete]

A discrete_distribution random number distribution produces random integers i, 0 ≤ i < n, distributed according to the discrete probability function P(i | p0,…,pn-1) = pi .

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 .

template<class IntType = int>
class discrete_distribution{
public:
// types
typedef IntType result_type;
typedef unspecified param_type;

// constructor and reset functions
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();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& g, const param_type& parm);

// property functions
vector<double> probabilities() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
};


 discrete_distribution(); 

Effects: Constructs a discrete_distribution object with n = 1 and p0 = 1 . [ Note: Such an object will always deliver the value 0.  — end note ]

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

Requires: InputIterator shall satisfy the requirements of an input iterator (Table [tab:iterator.input.requirements]) type. Moreover, iterator_traits<InputIterator>::value_type shall denote a type that is convertible to double. If firstW == lastW, let n = 1 and w0 = 1 . Otherwise, [firstW, lastW) shall form a sequence w of length n > 0.

Effects: Constructs a discrete_distribution object with probabilities given by the formula above.

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

Requires: Each instance of type UnaryOperation shall be a function object ([function.objects]) whose return type shall be convertible to double. Moreover, double shall be convertible to the type of UnaryOperation's sole parameter. If nw = 0 , let n = 1 , otherwise let n = nw. The relation 0 < δ = (xmax - xmin) / n shall hold.

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 .

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

 vector<double> probabilities() const; 

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

#### 26.5.8.6.2 Class template piecewise_constant_distribution[rand.dist.samp.pconst]

A piecewise_constant_distribution random number distribution produces random numbers x, b0x < bn , uniformly distributed over each subinterval [ bi, bi+1 ) according to the probability density function p(x | b0,…,bn, ρ0,…,ρn-1) = ρi , for bix < bi+1 .

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 distribution parameters are calculated as: 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 .

template<class RealType = double>
class piecewise_constant_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructor and reset functions
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();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


 piecewise_constant_distribution(); 

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

Requires: InputIteratorB and InputIteratorW shall each satisfy the requirements of an input iterator (Table [tab:iterator.input.requirements]) type. Moreover, iterator_traits<InputIteratorB>::value_type and iterator_traits<InputIteratorW>::value_type shall each denote a type that is convertible to double. If firstB == lastB or ++firstB == lastB, let n = 1 , w0 = 1 , b0 = 0 , and b1 = 1 . Otherwise, [firstB, lastB) shall form a sequence b of length n+1, the length of the sequence w starting from firstW shall be at least n, and any wk for kn shall be 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); 

Requires: Each instance of type UnaryOperation shall be a function object ([function.objects]) whose return type shall be convertible to double. Moreover, double shall be convertible to the type of UnaryOperation's sole parameter.

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 .

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

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

Requires: Each instance of type UnaryOperation shall be a function object ([function.objects]) whose return type shall be convertible to double. Moreover, double shall be convertible to the type of UnaryOperation's sole parameter. If nw = 0 , let n = 1 , otherwise let n = nw. The relation 0 < δ = (xmax - xmin) / n shall hold.

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 .

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

 vector<result_type> intervals() const; 

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; 

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 .

#### 26.5.8.6.3 Class template piecewise_linear_distribution[rand.dist.samp.plinear]

A piecewise_linear_distribution random number distribution produces random numbers x, b0x < bn , distributed over each subinterval [ bi, bi+1 ) according to the probability density function

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:

template<class RealType = double>
class piecewise_linear_distribution{
public:
// types
typedef RealType result_type;
typedef unspecified param_type;

// constructor and reset functions
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();

// generating functions
template<class URNG>
result_type operator()(URNG& g);
template<class URNG>
result_type operator()(URNG& 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;
};


 piecewise_linear_distribution(); 

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

Requires: InputIteratorB and InputIteratorW shall each satisfy the requirements of an input iterator (Table [tab:iterator.input.requirements]) type. Moreover, iterator_traits<InputIteratorB>::value_type and iterator_traits<InputIteratorW>::value_type shall each denote a type that is convertible to double. If firstB == lastB or ++firstB == lastB, let n = 1 , ρ0 = ρ1 = 1 , b0 = 0 , and b1 = 1 . Otherwise, [firstB, lastB) shall form a sequence b of length n+1, the length of the sequence w starting from firstW shall be at least n+1, and any wk for kn+1 shall be 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); 

Requires: Each instance of type UnaryOperation shall be a function object ([function.objects]) whose return type shall be convertible to double. Moreover, double shall be convertible to the type of UnaryOperation's sole parameter.

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 .

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

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

Requires: Each instance of type UnaryOperation shall be a function object ([function.objects]) whose return type shall be convertible to double. Moreover, double shall be convertible to the type of UnaryOperation's sole parameter. If nw = 0 , let n = 1 , otherwise let n = nw. The relation 0 < δ = (xmax - xmin) / n shall hold.

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 .

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

 vector<result_type> intervals() const; 

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; 

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 .