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

履歴 編集

function
<random>

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

result_type operator()();

概要

乱数生成を行う。

効果

ランダムな値を生成し、内部状態を進める。

戻り値

ランダムな値を生成して返す。
値の範囲は[min(), max()]である。つまり、最小値と最大値両方を含む。

計算量

償却定数時間

#include <iostream>
#include <random>

int main()
{
  std::minstd_rand engine;

  for (int i = 0; i < 10; ++i) {
    // 乱数生成
    std::uint32_t result = engine();

    std::cout << result << std::endl;
  }
}

出力例

48271
182605794
1291394886
1914720637
2078669041
407355683
1105902161
854716505
564586691
1596680831

バージョン

言語

  • C++11

処理系

参照