Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Constructs the engine.
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);
Parameters
x0
The seed value.Gen
The type of the seed generator.gen
The seed generator.right
A linear_congruential object.
Remarks
The first constructor constructs a linear_congruential object and initializes it by calling seed(x0). The second constructor constructs a linear_congruential object and initializes it by calling seed(gen). The third and fourth constructors construct a linear_congruential object by copying a linear_congruential object.
Example
// 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);
}
A == 16807 C == 0 M == 2147483647 min == 1 max == 2147483646 a random value == 16807 a random value == 282475249 a random value == 1622650073
Requirements
Header: <random>
Namespace: std