---
name: "std::linear_congruential_engine"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/std::linear_congruential_engine"
---

# std::linear\_congruential\_engine(3)

A model of a linear congruential random number generator.

## NAME

std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \> - A model of a linear congruential random number generator.

## SYNOPSIS

\#include \<random\>

### Public Types

typedef \_UIntType **result\_type**\

### Public Member Functions

**linear\_congruential\_engine** ()\
 Constructs a linear\_congruential\_engine random number generator engine with seed 1.  template\<typename \_Sseq, typename = \_If\_seed\_seq\<\_Sseq\>\> **linear\_congruential\_engine** (\_Sseq &\_\_q)\
 Constructs a linear\_congruential\_engine random number generator engine seeded from the seed sequence \_\_q.  **linear\_congruential\_engine** (**result\_type** \_\_s)\
 Constructs a linear\_congruential\_engine random number generator engine with seed \_\_s. The default seed value is 1.  void **discard** (unsigned long long \_\_z)\
 Discard a sequence of random numbers.  **result\_type** **operator()** ()\
 Gets the next random number in the sequence.  template\<typename \_Sseq\> \_If\_seed\_seq\< \_Sseq \> **seed** (\_Sseq &\_\_q)\
 Reseeds the linear\_congruential\_engine random number generator engine sequence using values from the seed sequence \_\_q.  void **seed** (**result\_type** \_\_s=default\_seed)\
 Reseeds the linear\_congruential\_engine random number generator engine sequence to the seed \_\_s.

### Static Public Member Functions

static constexpr **result\_type** **max** ()\
 Gets the largest possible value in the output range.  static constexpr **result\_type** **min** ()\
 Gets the smallest possible value in the output range.

### 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)\
 Writes the textual representation of the state x(i) of x to \_\_os.  bool **operator==** (const **linear\_congruential\_engine** &\_\_lhs, const **linear\_congruential\_engine** &\_\_rhs)\
 Compares two linear congruential random number generator objects of the same type for equality.  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)\
 Sets the state of the engine by reading its textual representation from \_\_is.

## 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 $1$.

**Since**

C++11

## Member Typedef Documentation

### 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.

## Constructor & Destructor Documentation

### 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.

### template\<typename \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \>::linear\_congruential\_engine (result\_type \_\_s) \[inline\], \[explicit\]

Constructs a linear\_congruential\_engine random number generator engine with seed \_\_s. The default seed value is 1.

**Parameters**

*\_\_s* The initial seed value.

### 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) \[inline\], \[explicit\]

Constructs a linear\_congruential\_engine random number generator engine seeded from the seed sequence \_\_q.

**Parameters**

*\_\_q* the seed sequence.

## Member Function Documentation

### 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.

### template\<typename \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> constexpr result\_type std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \>::max () \[inline\], \[static\], \[constexpr\]

Gets the largest possible value in the output range.

### template\<typename \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> constexpr result\_type std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \>::min () \[inline\], \[static\], \[constexpr\]

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.

### 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.

### 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.

References **std::\_\_lg()**, **std::\_\_numeric\_limits\_base::digits**, and **seed()**.

### 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.

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

### 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.

### 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.

### 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

### template\<typename \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> result\_type std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \>::increment \[static\], \[constexpr\]

An increment.

### template\<typename \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> result\_type std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \>::modulus \[static\], \[constexpr\]

The modulus.

### template\<typename \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> result\_type std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \>::multiplier \[static\], \[constexpr\]

The multiplier.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
