linear_congruential クラス

更新 : 2007 年 11 月

線形合同法アルゴリズムでランダム シーケンスを生成します。

template<class UIntType,
      UIntType A, UIntType C, UIntType M>
   class linear_congruential {
public:
      typedef linear_congruential<UIntType, A, C, M> _MyT;
   typedef UIntType result_type;
   static const UIntType multiplier = A;
   static const UIntType increment = C;
   static const UIntType modulus = M;
      static const UIntType default_seed = 1U;
      explicit linear_congruential(UIntType x0 = default_seed)
      linear_congruential(const linear_congruential& right);
      linear_congruential(linear_congruential& right);
   template<class Gen>
      linear_congruential(Gen& gen);
   void seed(UIntType x0 = default_seed);
   template<class Gen>
      void seed(Gen& gen);
   result_type min() const;
   result_type max() const;
   result_type operator()();
private:
   result_type stored_value;    // exposition only
   };

パラメータ

  • UIntType
    結果を表す符号なし整数型。

  • A
    A エンジン パラメータ。

  • C
    C エンジン パラメータ。

  • M
    M エンジン パラメータ。

解説

このテンプレート クラスは、ユーザーによって指定された符号なし整数型の値を、循環関係 x(i) = (A * x(i-1) + C) mod M を使って生成する単体エンジンを表します。エンジンの状態は、最後に返された値、またはシード値 (operator() が呼び出されなかった場合) になります。

テンプレートの引数 UIntType には、最大 M - 1 の値を保持できるだけの大きさが必要です。テンプレートの引数 A および C の値は M より小さくする必要があります。

必要条件

ヘッダー : <random>

名前空間 : std::tr1

参照

参照

<random>

linear_congruential クラス