linear_congruential::linear_congruential

构造引擎。

explicit linear_congruential(UIntType x0 = default_seed)
template<class Gen>
    linear_congruential(Gen& gen);
linear_congruential(const linear_congruential& right);
linear_congruential(linear_congruential& right);

参数

  • x0
    种子值。

  • Gen
    种子生成器的类型。

  • gen
    种子生成器。

  • right
    linear_congruential 对象。

备注

第一个构造函数构造 linear_congruential 对象并通过调用 seed(x0)将其初始化。第二个构造函数构造 linear_congruential 对象并通过调用 seed(gen)将其初始化。第三个和第四个构造函数通过复制 linear_congruential 对象构造 linear_congruential 对象。

示例

 

// std_tr1__random__linear_congruential_construct.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 Class