thrust::random::linear_congruential_engine
Defined in thrust/random/linear_congruential_engine.h
- 
template<typename UIntType, UIntType a, UIntType c, UIntType m>
 class linear_congruential_engine
- A - linear_congruential_enginerandom number engine produces unsigned integer random numbers using a linear congruential random number generation algorithm.- The generation algorithm has the form - x_i = (a * x_{i-1} + c) mod m.- The following code snippet shows examples of use of a - linear_congruential_engineinstance:- #include <thrust/random/linear_congruential_engine.h> #include <iostream> int main() { // create a minstd_rand object, which is an instance of linear_congruential_engine thrust::minstd_rand rng1; // output some random values to cout std::cout << rng1() << std::endl; // a random value is printed // create a new minstd_rand from a seed thrust::minstd_rand rng2(13); // discard some random values rng2.discard(13); // stream the object to an iostream std::cout << rng2 << std::endl; // rng2's current state is printed // print the minimum and maximum values that minstd_rand can produce std::cout << thrust::minstd_rand::min << std::endl; std::cout << thrust::minstd_rand::max << std::endl; // the range of minstd_rand is printed // save the state of rng2 to a different object thrust::minstd_rand rng3 = rng2; // compare rng2 and rng3 std::cout << (rng2 == rng3) << std::endl; // 1 is printed // re-seed rng2 with a different seed rng2.seed(7); // compare rng2 and rng3 std::cout << (rng2 == rng3) << std::endl; // 0 is printed return 0; } - See also - See also - Note - Inexperienced users should not use this class template directly. Instead, use - minstd_randor- minstd_rand0.- Template Parameters
- UIntType – The type of unsigned integer to produce. 
- a – The multiplier used in the generation algorithm. 
- c – The increment used in the generation algorithm. 
- m – The modulus used in the generation algorithm. 
 
 - Public Types - 
typedef UIntType result_type
- The type of the unsigned integer produced by this - linear_congruential_engine.
 - Public Functions - 
explicit linear_congruential_engine(result_type s = default_seed)
- This constructor, which optionally accepts a seed, initializes a new - linear_congruential_engine.- Parameters
- s – The seed used to initialize this - linear_congruential_engine'sstate.
 
 - 
void seed(result_type s = default_seed)
- This method initializes this - linear_congruential_engine'sstate, and optionally accepts a seed value.- Parameters
- s – The seed used to initializes this - linear_congruential_engine'sstate.
 
 - 
result_type operator()(void)
- This member function produces a new random value and updates this - linear_congruential_engine'sstate.- Returns
- A new random number. 
 
 - 
void discard(unsigned long long z)
- This member function advances this - linear_congruential_engine'sstate a given number of times and discards the results.- Note - This function is provided because an implementation may be able to accelerate it. - Parameters
- z – The number of random values to discard. 
 
 - Public Static Attributes - 
static const result_type multiplier = a
- The multiplier used in the generation algorithm. 
 - 
static const result_type increment = c
- The increment used in the generation algorithm. 
 - 
static const result_type modulus = m
- The modulus used in the generation algorithm. 
 - 
static const result_type min = 0u
- The smallest value this - linear_congruential_enginemay potentially produce.
 - 
static const result_type max = m - 1u
- The largest value this - linear_congruential_enginemay potentially produce.
 - 
static const result_type default_seed = 1u
- The default seed of this - linear_congruential_engine.