26 Numerics library [numerics]

26.6 Random number generation [rand]

26.6.8 Random number distribution class templates [rand.dist]

26.6.8.6 Sampling distributions [rand.dist.samp]

26.6.8.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 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 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:
template<class RealType = double>
  class piecewise_linear_distribution {
  public:
    // types
    using 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<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 URBG>
      result_type operator()(URBG& g);
    template<class URBG>
      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;
  };
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: is_­invocable_­r_­v<double, UnaryOperation&, double> is true.
Preconditions: InputIteratorB and InputIteratorW each meet the Cpp17InputIterator requirements ([input.iterators]).
If firstB == lastB or ++firstB == lastB, let , , , and .
Otherwise, 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 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 .