29.6 Random number generation [rand]
29.6.8 Random number distribution class templates [rand.dist]
A
discrete_distribution random number distribution
produces random integers
i, ,
distributed according to
the discrete probability function
Unless specified otherwise,
the 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:
.
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();
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;
};
discrete_distribution();
Effects: Constructs a
discrete_distribution object
with
and
. [
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 (
[input.iterators])
. Moreover,
iterator_traits<InputIterator>::value_type
shall denote a type that is convertible to
double. If
firstW == lastW,
let
and
. Otherwise,
shall form a sequence
w of length
.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 , let , otherwise let
. Effects: Constructs a
discrete_distribution object
with probabilities given by the formula above,
using the following values:
If ,
let
. 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
when invoked with argument
k for
. A
piecewise_constant_distribution random number distribution
produces random numbers
x,
,
uniformly distributed over each subinterval
according to the probability density function
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:
.
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();
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;
};
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);
Requires:
InputIteratorB and
InputIteratorW
shall each satisfy the requirements
of an input iterator (Table
90) 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 ,
,
,
and
. Otherwise,
shall form a sequence
b of length ,
the length of the sequence
w starting from
firstW
shall be at least
n,
and any for 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 ,
let ,
,
,
and
. Otherwise,
let
form a sequence ,
and
let
for
.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 , let , otherwise let
. 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 shall 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
. A
piecewise_linear_distribution random number distribution
produces random numbers
x,
,
distributed over each subinterval
according to the probability density function
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
,
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:
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();
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;
};
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);
Requires:
InputIteratorB and
InputIteratorW
shall each satisfy the requirements
of an input iterator (Table
90) 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 ,
,
,
and
. Otherwise,
shall form a sequence
b of length ,
the length of the sequence
w starting from
firstW
shall be at least ,
and any for 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 ,
let ,
,
,
and
. Otherwise,
let
form a sequence ,
and
let
for
.Complexity:
The number of invocations of
fw shall not exceed
. 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 , let , otherwise let
. 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 shall 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
.