最終更新日時(UTC):
が更新

履歴 編集

function template
<random>

std::poisson_distribution::operator()(C++11)

template <class URBG>
result_type operator()(URBG& g);                         // (1)

template <class URBG>
result_type operator()(URBG& g, const param_type& parm); // (2)

概要

  • (1) : コンストラクタで指定されたパラメータに基いて、乱数生成を行う
  • (2) : コンストラクタで設定されたパラメータの代わりに、paramを乱数生成のパラメータとして使用して乱数生成を行う

戻り値

指定されたパラメータに基いて、分布したランダムな値を生成して返す。

計算量

償却定数時間(g()の呼び出し回数)

#include <iostream>
#include <random>

int main()
{
  std::random_device seed_gen;
  std::default_random_engine engine(seed_gen());

  // (1)
  {
    std::poisson_distribution<> dist(1.0);

    for (int i = 0; i < 5; ++i) {
      int result = dist(engine);
      std::cout << result << std::endl;
    }
  }

  // (2) パラメータを渡すバージョン
  std::cout << std::endl;
  {
    using dist_type = std::poisson_distribution<>;
    dist_type dist;

    for (int i = 0; i < 5; ++i) {
      dist_type::param_type param(1.0);
      int result = dist(engine, param);
      std::cout << result << std::endl;
    }
  }
}

出力例

3
1
1
1
1

1
2
0
1
0

バージョン

言語

  • C++11

処理系

参照