Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::discrete_distribution<IntType>::discrete_distribution

      From cppreference.com
      <cpp‎ |numeric‎ |random‎ |discrete distribution
       
       
       
      Pseudo-random number generation
       
       
      discrete_distribution();
      (1)(since C++11)
      template<class InputIt>
      discrete_distribution( InputIt first, InputIt last);
      (2)(since C++11)
      discrete_distribution(std::initializer_list<double> weights);
      (3)(since C++11)
      template<class UnaryOperation>

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

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

      Constructs a new distribution object.

      1) Default constructor. Constructs the distribution with a single weightp = {1}. This distribution will always generate0.
      2) Constructs the distribution with weights in the range[firstlast). Iffirst== last, the effects are the same as of the default constructor.
      3) Constructs the distribution with weights inweights. Effectively callsdiscrete_distribution(weights.begin(), weights.end()).
      4) Constructs the distribution withcount weights that are generated using functionunary_op. Each of the weights is equal towi = unary_op(xmin + δ(i + 0.5)), whereδ =
      (xmax − xmin)
      count
      andi ∈ {0, ..., count − 1}.xmin andxmax must be such thatδ > 0. Ifcount==0 the effects are the same as of the default constructor.
      5) Constructs the distribution withparams as the distribution parameters.

      [edit]Parameters

      first, last - the range of elements defining the numbers to use as weights. The type of the elements referred byInputIterator must be convertible todouble
      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 haveconst&.
      The type Type must be such that an object of typedouble can be dereferenced and then implicitly converted to Type. The typeRet must be such that an object of typedouble can be dereferenced and assigned a value of typeRet.​

      params - the distribution parameter set
      Type requirements
      -
      InputIt must meet the requirements ofLegacyInputIterator.
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/random/discrete_distribution/discrete_distribution&oldid=151206"

      [8]ページ先頭

      ©2009-2025 Movatter.jp