std::discrete_distribution<IntType>::discrete_distribution

From cppreference.com
 
 
Numerics library
Common mathematical functions
Mathematical special functions (哋它亢++17)
Mathematical constants (哋它亢++20)
Basic linear algebra algorithms (哋它亢++26)
Floating-point environment (哋它亢++11)
Complex numbers
Numeric arrays
Pseudo-random number generation
Factor operations
(哋它亢++17)
(哋它亢++17)
Interpolations
(哋它亢++20)
(哋它亢++20)
Saturation arithmetic
(哋它亢++26)
(哋它亢++26)
(哋它亢++26)
(哋它亢++26)
(哋它亢++26)

Generic numeric operations
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
Bit operations
(哋它亢++20)    
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++23)
(哋它亢++20)
 
Pseudo-random number generation
Uniform random bit generators
Random number engines
Random number engine adaptors
(哋它亢++11)
(哋它亢++11)
Predefined random number generators
Non-deterministic random numbers
(哋它亢++11)
Random number distributions
Uniform distributions
(哋它亢++11)
Bernoulli distributions
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
Poisson distributions
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
Normal distributions
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
Sampling distributions
(哋它亢++11)
Utilities
(哋它亢++11)
(哋它亢++11)
Random number algorithms
C random library
 
std::discrete_distribution
Member functions
discrete_distribution::discrete_distribution
(哋它亢++11)
Generation
Characteristics
Non-member functions
(哋它亢++11)(哋它亢++11)(until 哋它亢++20)
(哋它亢++11)(哋它亢++11)
 
discrete_distribution();
(1) (since 哋它亢++11)
template< class InputIt >
discrete_distribution( InputIt first, InputIt last );
(2) (since 哋它亢++11)
discrete_distribution( std::initializer_list<double> weights );
(3) (since 哋它亢++11)
template< class UnaryOperation >

discrete_distribution( std::size_t count, double xmin, double xmax,

                       UnaryOperation unary_op );
(4) (since 哋它亢++11)
explicit discrete_distribution( const param_type& params );
(5) (since 哋它亢++11)

Constructs a new distribution object.

1) Default constructor. Constructs the distribution with a single weight p = {1}. This distribution will always generate 0.
2) Constructs the distribution with weights in the range [firstlast). If first == last, the effects are the same as of the default constructor.
3) Constructs the distribution with weights in weights. Effectively calls discrete_distribution(weights.begin(), weights.end()).
4) Constructs the distribution with count weights that are generated using function unary_op. Each of the weights is equal to w
i
= unary_op(xmin + δ(i + 0.5))
, where δ =
(xmax − xmin)
count
and i ∈ {0, ..., count − 1}. xmin and xmax must be such that δ > 0. If count == 0 the effects are the same as of the default constructor.
5) Constructs the distribution with params as the distribution parameters.

Parameters

first, last - the range of elements defining the numbers to use as weights. The type of the elements referred by InputIterator must be convertible to double
weights - initializer list containing the weights
unary_op - unary operation function object that will be applied.

The signature of the function should be equivalent to the following:

 Ret fun(const Type &a);

The signature does not need to have const &.
The type  Type must be such that an object of type double can be dereferenced and then implicitly converted to  Type. The type Ret must be such that an object of type double can be dereferenced and assigned a value of type Ret. ​

params - the distribution parameter set
Type requirements
-
InputIt must meet the requirements of LegacyInputIterator.