libstdc++: std::linear_congruential_engine< _UIntType, __a, __c, __m > Class Template Reference

libstdc++

std::linear_congruential_engine< _UIntType, __a, __c, __m > Class Template Reference
Numerics » Random Number Generation » Random Number Generators

`#include <random>`

## Public Types
typedef _UIntType | result_type

## Public Member Functions
| linear_congruential_engine ()
template<typename _Sseq, typename = _If_seed_seq<_Sseq>>
| linear_congruential_engine (_Sseq &__q)
| linear_congruential_engine (result_type __s)
void | discard (unsigned long long __z)
result_type | operator() ()
template<typename _Sseq>
_If_seed_seq< _Sseq > | seed (_Sseq &__q)
void | seed (result_type __s=default_seed)

## Static Public Member Functions
static constexpr result_type | max ()
static constexpr result_type | min ()

## Static Public Attributes
static constexpr result_type | default_seed
static constexpr result_type | increment
static constexpr result_type | modulus
static constexpr result_type | multiplier

## Friends
template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1, _UIntType1 __m1, typename _CharT, typename _Traits>
std::basic_ostream< _CharT, _Traits > & | operator<< (std::basic_ostream< _CharT, _Traits > &__os, const std::linear_congruential_engine< _UIntType1, __a1, __c1, __m1 > &__lcr)
bool | operator== (const linear_congruential_engine &__lhs, const linear_congruential_engine &__rhs)
template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1, _UIntType1 __m1, typename _CharT, typename _Traits>
std::basic_istream< _CharT, _Traits > & | operator>> (std::basic_istream< _CharT, _Traits > &__is, std::linear_congruential_engine< _UIntType1, __a1, __c1, __m1 > &__lcr)

## Detailed Description

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
class std::linear_congruential_engine< _UIntType, __a, __c, __m >

A model of a linear congruential random number generator.

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

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 .

Since
  C++11

Definition at line 703 of file random.h.

## Member Typedef Documentation

## ◆ result_type

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

typedef _UIntType std::linear_congruential_engine< _UIntType, __a, __c, __m >::result_type

The type of the generated random value.

Definition at line 716 of file random.h.

## Constructor & Destructor Documentation

## ◆ linear_congruential_engine() [1/3]

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

std::linear_congruential_engine< _UIntType, __a, __c, __m >::linear_congruential_engine | ( |  | ) |
| inline

Constructs a linear_congruential_engine random number generator engine with seed 1.

Definition at line 730 of file random.h.

## ◆ linear_congruential_engine() [2/3]

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

std::linear_congruential_engine< _UIntType, __a, __c, __m >::linear_congruential_engine | ( | result_type | __s | ) |
| inlineexplicit

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

Parameters

  __s | The initial seed value.

Definition at line 741 of file random.h.

## ◆ linear_congruential_engine() [3/3]

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
template<typename _Sseq, typename = _If_seed_seq<_Sseq>>

std::linear_congruential_engine< _UIntType, __a, __c, __m >::linear_congruential_engine | ( | _Sseq & | __q | ) |
| inlineexplicit

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

Parameters

  __q | the seed sequence.

Definition at line 752 of file random.h.

## Member Function Documentation

## ◆ discard()

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

void std::linear_congruential_engine< _UIntType, __a, __c, __m >::discard | ( | unsigned long long | __z | ) |
| inline

Discard a sequence of random numbers.

Definition at line 796 of file random.h.

## ◆ max()

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

constexpr result_type std::linear_congruential_engine< _UIntType, __a, __c, __m >::max | ( |  | ) |
| inlinestaticconstexpr

Gets the largest possible value in the output range.

Definition at line 789 of file random.h.

## ◆ min()

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

constexpr result_type std::linear_congruential_engine< _UIntType, __a, __c, __m >::min | ( |  | ) |
| inlinestaticconstexpr

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 782 of file random.h.

## ◆ operator()()

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

result_type std::linear_congruential_engine< _UIntType, __a, __c, __m >::operator() | ( |  | ) |
| inline

Gets the next random number in the sequence.

Definition at line 806 of file random.h.

## ◆ seed() [1/2]

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
template<typename _Sseq>

auto std::linear_congruential_engine< _UIntType, __a, __c, __m >::seed | ( | _Sseq & | __q | ) | -> _If_seed_seq< _Sseq >

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

Parameters

  __q | the seed sequence.

Seeds the LCR engine with a value generated by `__q`.

Definition at line 134 of file bits/random.tcc.

References std::__lg(), std::__numeric_limits_base::digits, and seed().

## ◆ seed() [2/2]

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

void std::linear_congruential_engine< _UIntType, __a, __c, __m >::seed | ( | result_type | __s = default_seed | ) |

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

Parameters

  __s | The 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 118 of file bits/random.tcc.

Referenced by std::linear_congruential_engine< uint_fast32_t, 16807UL, 0UL, 2147483647UL >::linear_congruential_engine(), std::linear_congruential_engine< uint_fast32_t, 16807UL, 0UL, 2147483647UL >::linear_congruential_engine(), and seed().

## Friends And Related Symbol Documentation

## ◆ operator<<

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1, _UIntType1 __m1, typename _CharT, typename _Traits>

std::basic_ostream< _CharT, _Traits > & operator<< | ( | std::basic_ostream< _CharT, _Traits > & | __os,
|  | const std::linear_congruential_engine< _UIntType1, __a1, __c1, __m1 > & | __lcr )
| friend

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

Parameters

  __os | The output stream.
  __lcr | A % linear_congruential_engine random number generator.

Returns
  __os.

## ◆ operator==

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

bool operator== | ( | const linear_congruential_engine< _UIntType, __a, __c, __m > & | __lhs,
|  | const linear_congruential_engine< _UIntType, __a, __c, __m > & | __rhs )
| friend

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

Parameters

  __lhs | A linear congruential random number generator object.
  __rhs | Another linear congruential random number generator object.

Returns
  true if the infinite sequences of generated values would be equal, false otherwise.

Definition at line 824 of file random.h.

## ◆ operator>>

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>
template<typename _UIntType1, _UIntType1 __a1, _UIntType1 __c1, _UIntType1 __m1, typename _CharT, typename _Traits>

std::basic_istream< _CharT, _Traits > & operator>> | ( | std::basic_istream< _CharT, _Traits > & | __is,
|  | std::linear_congruential_engine< _UIntType1, __a1, __c1, __m1 > & | __lcr )
| 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

  __is | The input stream.
  __lcr | A % linear_congruential_engine random number generator.

Returns
  __is.

## Member Data Documentation

## ◆ default_seed

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

result_type std::linear_congruential_engine< _UIntType, __a, __c, __m >::default_seed
| staticconstexpr

Definition at line 724 of file random.h.

## ◆ increment

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

result_type std::linear_congruential_engine< _UIntType, __a, __c, __m >::increment
| staticconstexpr

An increment.

Definition at line 721 of file random.h.

## ◆ modulus

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

result_type std::linear_congruential_engine< _UIntType, __a, __c, __m >::modulus
| staticconstexpr

The modulus.

Definition at line 723 of file random.h.

## ◆ multiplier

template<typename _UIntType, _UIntType __a, _UIntType __c, _UIntType __m>

result_type std::linear_congruential_engine< _UIntType, __a, __c, __m >::multiplier
| staticconstexpr

The multiplier.

Definition at line 719 of file random.h.

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

- random.h
- bits/random.tcc