次の方法で共有


linear_congruential::seed

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

void seed(UIntType x0 = default_seed);
template<class Gen>
    void seed(Gen& gen);

パラメーター

  • x0
    シード値。

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

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

解説

1 つ目のシード関数は、c mod M == 0 かつ x0 mod M == 0 の場合、格納されている値 stored_value を 1 mod M に設定します。それ以外の場合は、格納されている値を x0 mod M に設定します。2 つ目のシード関数は、seed(gen()) を呼び出します。

使用例

 

// std_tr1__random__linear_congruential_seed.cpp 
// compile with: /EHsc 
#include <random> 
#include <iostream> 
 
typedef std::mt19937 Myeng; 
typedef std::linear_congruential<int, 16807, 0, 
    (int)((1U << 31) - 1)> Myceng;  // same as minstd_rand0 
int main() 
    { 
    Myeng eng; 
    Myceng ceng; 
    Myceng::result_type compval = ceng(); 
 
    compval = compval;  // to quiet "unused" warnings 
 
    std::cout << "A == " << Myceng::multiplier << std::endl; 
    std::cout << "C == " << Myceng::increment << std::endl; 
    std::cout << "M == " << Myceng::modulus << 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 
 
    return (0); 
    } 
 
  

必要条件

ヘッダー : <random>

名前空間: std

参照

関連項目

<random>

linear_congruential クラス