名前空間
変種
操作

std::linear_congruential_engine

From cppreference.com
< cpp‎ | numeric‎ | random
 
 
 
 
 
ヘッダー <random> で定義
template<

    class UIntType,
    UIntType a,
    UIntType c,
    UIntType m

> class linear_congruential_engine;
(C++11以降)

linear_congruential_engineは、線形合同法ジェネレータ(LCG)に基づいた乱数エンジンです。

目次

[編集] テンプレートパラメータ

UIntType - ジェネレータによって生成される結果の型。これがunsigned shortunsigned intunsigned long、またはunsigned long longのいずれでもない場合、動作は未定義です。
a - 乗数項
c - 加算項
m - 法項

mがゼロでない場合、a >= mまたはc >= mtrueである場合、プログラムは不適切に形成されます。

[編集] ジェネレータのプロパティ

linear_congruential_engineの状態のサイズ1であり、それぞれが単一の整数で構成されます。

実際の法m0は次のように定義されます。

  • もしmがゼロでないなら、m0mです。
  • もしmがゼロなら、m0std::numeric_limits<result_type>::max()1を加えた値です(これはm0result_typeとして表現可能である必要がないことを意味します)。

linear_congruential_engine遷移アルゴリズムTA(xi) = (a·xi+c) mod m0です。

linear_congruential_engine生成アルゴリズムGA(xi) = (a·xi+c) mod m0です。

現在の状態から生成される疑似乱数は、次の状態でもあります。

[編集] 定義済みの特殊化

以下の特殊化は、一般的に使用される2つのパラメータセットを持つ乱数エンジンを定義します。

ヘッダー <random> で定義
定義
minstd_rand0 (C++11) std::linear_congruential_engine<std::uint_fast32_t,
                                16807, 0, 2147483647>

1969年にLewis、Goodman、Millerによって発見され、1988年にParkとMillerによって「最小標準」として採用された[編集]

minstd_rand (C++11)

std::linear_congruential_engine<std::uint_fast32_t,
                                48271, 0, 2147483647>
新しい「最小標準」。1993年にPark、Miller、Stockmeyerによって推奨された[編集]

[編集] ネストされた型

定義
result_type UIntType

[編集] データメンバー

constexpr UIntType multiplier
[static]
a
(公開静的メンバ定数)
constexpr UIntType increment
[static]
c
(公開静的メンバ定数)
constexpr UIntType modulus
[static]
m
(公開静的メンバ定数)
constexpr UIntType default_seed
[static]
1u
(公開静的メンバ定数)

[編集] メンバ関数

構築とシード
エンジンを構築します。
(public member function) [編集]
エンジンの現在の状態を設定します。
(public member function) [編集]
生成
エンジンの状態を進め、生成された値を返す
(public member function) [編集]
指定された量だけエンジンの状態を進めます。
(public メンバ関数) [編集]
特性
[static]
出力範囲の最小値を返します。
(public static member function) [編集]
[static]
出力範囲の最大値を返します。
(public static member function) [編集]

[編集] 非メンバ関数

(C++11)(C++11)(C++20で削除)
2つの擬似乱数エンジンの内部状態を比較します。
(関数) [編集]
疑似乱数エンジンのストリーム入出力を実行
(関数テンプレート) [編集]

[編集]

English 日本語 中文(简体) 中文(繁體)