subtract_with_carry::seed

エンジンにシードを与えます。

void seed(result_type x0 = 19780503UL);
template<class Gen>
    void seed(Gen& gen);

パラメーター

  • Gen
    シード ジェネレーターの型。

  • gen
    シード ジェネレーター。

  • x0
    シード値。

解説

前提条件 : 0 < x0

1 つ目のシード関数は、gen の連続呼び出しによって返された unsigned long 型の値から、long_lag の履歴値を生成します。それぞれの履歴値は、gen() % modulus で求められます。

2 つ目のシード関数は、実質的に次のコードを実行します。

    linear_congruential<unsigned long, 40014, 0, 2147483563> gen(x0);
    seed(gen);

使用例

 

// std_tr1__random__subtract_with_carry_seed.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::mt19937 Myeng; 
typedef std::subtract_with_carry<unsigned int, 1 << 24, 
    10, 24> Myceng; 
int main() 
    { 
    Myeng eng; 
    Myceng ceng; 
    Myceng::result_type compval = ceng(); 
 
    compval = compval;  // to quiet "unused" warnings 
 
    std::cout << "M == " << Myceng::modulus << std::endl; 
    std::cout << "S == " << Myceng::short_lag << std::endl; 
    std::cout << "R == " << Myceng::long_lag << std::endl; 
 
    std::cout << "min == " << ceng.min() << std::endl; 
    std::cout << "max == " << ceng.max() << std::endl; 
 
    ceng.seed(); // reseed base engine 
    std::cout << "a random value == " << ceng() << std::endl; 
    std::cout << "a random value == " << ceng() << std::endl; 
    std::cout << "a random value == " << ceng() << std::endl; 
 
    Myceng ceng2(eng); // construct with generator 
    ceng2.seed(eng);  // seed with generator 
 
    Myceng ceng3(5UL);  // construct with unsigned long seed 
    ceng3.seed(5UL);  // seed with unsigned long 
 
    return (0); 
    } 
 
  

必要条件

ヘッダー : <random>

名前空間: std

参照

関連項目

<random>

subtract_with_carry クラス