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

履歴 編集

function template
<random>

std::student_t_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::student_t_distribution<> dist(1.0);

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

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

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

出力例

-0.392587
0.504807
0.00680619
-522.819
-46.2201

-2.07723
-0.305813
-1.41927
-0.430027
1.64272

バージョン

言語

  • C++11

処理系

参照