thrust
Public Types | Public Member Functions | Static Public Attributes | List of all members
thrust::random::linear_congruential_engine< UIntType, a, c, m > Class Template Reference

A linear_congruential_engine random number engine produces unsigned integer random numbers using a linear congruential random number generation algorithm. More...

#include <thrust/random/linear_congruential_engine.h>

Public Types

typedef UIntType result_type
 The type of the unsigned integer produced by this linear_congruential_engine.
 

Public Member Functions

__host__ __device__ linear_congruential_engine (result_type s=default_seed)
 
__host__ __device__ void seed (result_type s=default_seed)
 
__host__ __device__ result_type operator() (void)
 
__host__ __device__ void discard (unsigned long long z)
 

Static Public Attributes

static const result_type multiplier = a
 
static const result_type increment = c
 
static const result_type modulus = m
 
static const result_type min = c == 0u ? 1u : 0u
 
static const result_type max = m - 1u
 
static const result_type default_seed = 1u
 

Detailed Description

template<typename UIntType, UIntType a, UIntType c, UIntType m>
class thrust::random::linear_congruential_engine< UIntType, a, c, m >

A linear_congruential_engine random 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.

Template Parameters
UIntTypeThe type of unsigned integer to produce.
aThe multiplier used in the generation algorithm.
cThe increment used in the generation algorithm.
mThe modulus used in the generation algorithm.
Note
Inexperienced users should not use this class template directly. Instead, use minstd_rand or minstd_rand0.

The following code snippet shows examples of use of a linear_congruential_engine instance:

#include <iostream>
int main(void)
{
// create a minstd_rand object, which is an instance of linear_congruential_engine
// output some random values to cout
std::cout << rng1() << std::endl;
// a random value is printed
// create a new minstd_rand from a seed
// 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
thrust::random::minstd_rand
thrust::random::minstd_rand0

The documentation for this class was generated from the following file: