libstdc++
std::linear_congruential_engine Class Reference

List of all members.

Public Types

Public Member Functions

Static Public Member Functions

Static Public Attributes

Friends


Detailed Description

A model of a linear congruential random number generator.

A random number generator that produces pseudorandom numbers via linear function:

\[ x_{i+1}\leftarrow(ax_{i} + c) \bmod m \]

The template parameter _UIntType must be an unsigned integral type large enough to store values up to (__m-1). If the template parameter __m is 0, the modulus __m used is std::numeric_limits<_UIntType>::max() plus 1. Otherwise, the template parameters __a and __c must be less than __m.

The size of the state is $1$.


Member Typedef Documentation

The type of the generated random value.

Definition at line 179 of file random.h.


Constructor & Destructor Documentation

std::linear_congruential_engine::linear_congruential_engine ( result_type  __s = default_seed) [inline, explicit]

Constructs a linear_congruential_engine random number generator engine with seed __s. The default seed value is 1.

Parameters:
__sThe initial seed value.

Definition at line 197 of file random.h.

References seed().

template<typename _Sseq , typename = typename std::enable_if<!std::is_same<_Sseq, linear_congruential_engine>::value> ::type>
std::linear_congruential_engine::linear_congruential_engine ( _Sseq &  __q) [inline, explicit]

Constructs a linear_congruential_engine random number generator engine seeded from the seed sequence __q.

Parameters:
__qthe seed sequence.

Definition at line 210 of file random.h.

References seed().


Member Function Documentation

void std::linear_congruential_engine::discard ( unsigned long long  __z) [inline]

Discard a sequence of random numbers.

Definition at line 254 of file random.h.

static constexpr result_type std::linear_congruential_engine::max ( ) [inline, static]

Gets the largest possible value in the output range.

Definition at line 247 of file random.h.

static constexpr result_type std::linear_congruential_engine::min ( ) [inline, static]

Gets the smallest possible value in the output range.

The minimum depends on the __c parameter: if it is zero, the minimum generated must be > 0, otherwise 0 is allowed.

Definition at line 240 of file random.h.

result_type std::linear_congruential_engine::operator() ( ) [inline]

Gets the next random number in the sequence.

Definition at line 264 of file random.h.

void std::linear_congruential_engine::seed ( result_type  __s = default_seed)

Reseeds the linear_congruential_engine random number generator engine sequence to the seed __s.

Parameters:
__sThe new seed.

Seeds the LCR with integral value __s, adjusted so that the ring identity is never a member of the convergence set.

Definition at line 134 of file random.tcc.

Referenced by linear_congruential_engine().

template<typename _Sseq >
std::enable_if< std::is_class< _Sseq >::value >::type std::linear_congruential_engine::seed ( _Sseq &  __q)

Reseeds the linear_congruential_engine random number generator engine sequence using values from the seed sequence __q.

Parameters:
__qthe seed sequence.

Seeds the LCR engine with a value generated by __q.

Definition at line 150 of file random.tcc.

References std::__lg().


Friends And Related Function Documentation

template<typename _UIntType1 , _UIntType1 __a1, _UIntType1 __c1, _UIntType1 __m1, typename _CharT , typename _Traits >
std::basic_ostream<_CharT, _Traits>& operator<< ( std::basic_ostream< _CharT, _Traits > &  ,
const std::linear_congruential_engine< _UIntType1, __a1, __c1, __m1 > &   
) [friend]

Writes the textual representation of the state x(i) of x to __os.

Parameters:
__osThe output stream.
__lcrA % linear_congruential_engine random number generator.
Returns:
__os.
bool operator== ( const linear_congruential_engine __lhs,
const linear_congruential_engine __rhs 
) [friend]

Compares two linear congruential random number generator objects of the same type for equality.

Parameters:
__lhsA linear congruential random number generator object.
__rhsAnother linear congruential random number generator object.
Returns:
true if the infinite sequences of generated values would be equal, false otherwise.

Definition at line 282 of file random.h.

template<typename _UIntType1 , _UIntType1 __a1, _UIntType1 __c1, _UIntType1 __m1, typename _CharT , typename _Traits >
std::basic_istream<_CharT, _Traits>& operator>> ( std::basic_istream< _CharT, _Traits > &  ,
std::linear_congruential_engine< _UIntType1, __a1, __c1, __m1 > &   
) [friend]

Sets the state of the engine by reading its textual representation from __is.

The textual representation must have been previously written using an output stream whose imbued locale and whose type's template specialization arguments _CharT and _Traits were the same as those of __is.

Parameters:
__isThe input stream.
__lcrA % linear_congruential_engine random number generator.
Returns:
__is.

Member Data Documentation

constexpr _UIntType std::linear_congruential_engine::increment [static]

An increment.

Definition at line 184 of file random.h.

constexpr _UIntType std::linear_congruential_engine::modulus [static]

The modulus.

Definition at line 186 of file random.h.

constexpr _UIntType std::linear_congruential_engine::multiplier [static]

The multiplier.

Definition at line 182 of file random.h.


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