---
name: "std::linear_congruential_engine"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::linear_congruential_engine/3cxx"
---

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

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`.  template\<**typename** **\_Sseq** \> **auto** **seed** (**\_Sseq** &\_\_q) -\> \_If\_seed\_seq\< **\_Sseq** \>\
 **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:  \
     x\_{i+1} \]

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

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

References **std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \>::seed()**.

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

References **std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \>::seed()**.

## 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\> static 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\> static 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 \> \_If\_seed\_seq\< \_Sseq \> std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \>::seed (\_Sseq & \_\_q)

Reseeds the linear\_congruential\_engine random number generator engine sequence using values from the seed sequence `__q`.

**Parameters**

*\_\_q* the seed 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\>

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

References **std::\_\_lg()**.

### 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\< \_UIntType, \_\_a, \_\_c, \_\_m \>::linear\_congruential\_engine()**, and **std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \>::linear\_congruential\_engine()**.

## 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\> constexpr result\_type std::linear\_congruential\_engine\< \_UIntType, \_\_a, \_\_c, \_\_m \>::increment` [static]`, ` [constexpr]`

An increment.

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

The modulus.

### template\<typename \_UIntType , \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> constexpr 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.
