subtract_with_carry クラス

更新 : 2007 年 11 月

キャリー付き減算アルゴリズムでランダム シーケンスを生成します。

template<class IntType,
   IntType M, int S, int R>
   class subtract_with_carry {
public:
   typedef IntType result_type;
      typedef subtract_with_carry<IntType, M, S, R> _Myt;
   static const IntType modulus = M;
   static const IntType default_seed = 19780503U;
   static const int short_lag = S;
   static const int long_lag = R;
      subtract_with_carry();
   explicit subtract_with_carry(unsigned long x0 = default_seed);
   template<class Gen>
      subtract_with_carry(Gen& gen);
   subtract_with_carry(const subtract_with_carry& right);
   subtract_with_carry(subtract_with_carry& right);
   void seed(unsigned long x0 = 19780503UL);
   template<class Gen>
      void seed(Gen& gen);
   result_type min() const;
   result_type max() const;
   result_type operator()();
   };

パラメータ

  • IntType
    結果を表す整数型。

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

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

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

解説

このテンプレート クラスは、ユーザーによって指定された整数型の値を、循環関係 x(i) = (x(i - R) - x(i - S) - cy(i - 1)) mod M を使って生成する単体エンジンを表します。cy(i) は、x(i - S) - x(i - R) - cy(i - 1) < 0 の場合は 1 という値を、それ以外の場合は 0 を保持します。エンジンの状態は、operator() が少なくとも R 回呼び出された場合、返された最後の R 値になります。それ以外の場合は、返された M 値と、シードの最後の R - M 値になります。

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

必要条件

ヘッダー : <random>

名前空間 : std::tr1

参照

参照

<random>

subtract_with_carry クラス

subtract_with_carry_01 クラス