---
name: "std::linear_congruential"
section: "3cxx"
platform: "linux"
package: "libstdc++6-4.4-doc"
version: "4.4.7-2"
release: "Debian 7 (Wheezy)"
platforms: ["linux"]
url: "https://new.carta.tech/std::linear_congruential/3cxx"
---

# std::linear\_congruential(3cxx)

## NAME

std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \> -

## SYNOPSIS

### Public Types

typedef \_UIntType **result\_type**\

### Public Member Functions

**linear\_congruential** (unsigned long \_\_x0=1)\
 template\<class \_Gen \> **linear\_congruential** (\_Gen &\_\_g)\
 **result\_type** **max** () const \
 **result\_type** **min** () const \
 **result\_type** **operator()** ()\
 void **seed** (unsigned long \_\_s=1)\
 template\<class \_Gen \> void **seed** (\_Gen &\_\_g)\

### Static Public Attributes

static const \_UIntType **increment**\
 static const \_UIntType **modulus**\
 static const \_UIntType **multiplier**\

### Friends

bool **operator!=** (const **linear\_congruential** &\_\_lhs, const **linear\_congruential** &\_\_rhs)\
 template\<class \_UIntType1 , \_UIntType1 \_\_a1, \_UIntType1 \_\_c1, \_UIntType1 \_\_m1, typename \_CharT , typename \_Traits \> **std::basic\_ostream**\< \_CharT, \
 \_Traits \> & **operator\<\<** (**std::basic\_ostream**\< \_CharT, \_Traits \> &\_\_os, const **linear\_congruential**\< \_UIntType1, \_\_a1, \_\_c1, \_\_m1 \> &\_\_lcr)"\
 bool **operator==** (const **linear\_congruential** &\_\_lhs, const **linear\_congruential** &\_\_rhs)\
 template\<class \_UIntType1 , \_UIntType1 \_\_a1, \_UIntType1 \_\_c1, \_UIntType1 \_\_m1, typename \_CharT , typename \_Traits \> **std::basic\_istream**\< \_CharT, \
 \_Traits \> & **operator\>\>** (**std::basic\_istream**\< \_CharT, \_Traits \> &\_\_is, **linear\_congruential**\< \_UIntType1, \_\_a1, \_\_c1, \_\_m1 \> &\_\_lcr)"\

## Detailed Description

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\>class std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>

A model of a linear congruential random number generator.

A random number generator that produces pseudorandom numbers using the 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 $.

Definition at line 346 of file tr1\_impl/random.

## Member Typedef Documentation

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> typedef \_UIntType std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::result\_type

The type of the generated random value.

Definition at line 353 of file tr1\_impl/random.

## Constructor & Destructor Documentation

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::linear\_congruential (unsigned long\_\_x0 = `1`)` [inline]`, ` [explicit]`

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

**Parameters:**

*\_\_s* The initial seed value.

Definition at line 369 of file tr1\_impl/random.

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

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> template\<class \_Gen \> std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::linear\_congruential (\_Gen &\_\_g)` [inline]`

Constructs a linear\_congruential random number generator engine seeded from the generator function `__g`.

**Parameters:**

*\_\_g* The seed generator function.

Definition at line 379 of file tr1\_impl/random.

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

## Member Function Documentation

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> result\_type std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::max () const` [inline]`

Gets the largest possible value in the output range.

Definition at line 416 of file tr1\_impl/random.

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> result\_type std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::min () const` [inline]`

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 409 of file tr1\_impl/random.

### template\<class \_UIntType , \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::result\_type std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::operator() ()

Gets the next random number in the sequence.

Gets the next generated value in sequence.

Definition at line 130 of file random.tcc.

### template\<class \_UIntType , \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> void std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::seed (unsigned long\_\_x0 = `1`)

Reseeds the linear\_congruential random number generator engine sequence to the seed  \_\_s.

**Parameters:**

*\_\_s* The new seed.

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

Definition at line 98 of file random.tcc.

Referenced by std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::linear\_congruential().

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> template\<class \_Gen \> void std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::seed (\_Gen &\_\_g)` [inline]`

Reseeds the linear\_congruential random number generator engine sequence using values from the generator function `__g`.

**Parameters:**

*\_\_g* the seed generator function.

Definition at line 399 of file tr1\_impl/random.

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

Referenced by std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::seed().

## Friends And Related Function Documentation

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> bool operator!= (const linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \> &\_\_lhs, const linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \> &\_\_rhs)` [friend]`

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

**Parameters:**

*\_\_lhs* A linear congruential random number generator object. \
 *\_\_rhs* Another linear congruential random number generator obj.

**Returns:**

true if the two objects are not equal, false otherwise.

Definition at line 449 of file tr1\_impl/random.

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> template\<class \_UIntType1 , \_UIntType1 \_\_a1, \_UIntType1 \_\_c1, \_UIntType1 \_\_m1, typename \_CharT , typename \_Traits \> std::basic\_ostream\<\_CharT, \_Traits\>& operator\<\< (std::basic\_ostream\< \_CharT, \_Traits \> &\_\_os, const linear\_congruential\< \_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** random number generator.

**Returns:**

\_\_os.

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> bool operator== (const linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \> &\_\_lhs, const linear\_congruential\< \_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 obj.

**Returns:**

true if the two objects are equal, false otherwise.

Definition at line 435 of file tr1\_impl/random.

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> template\<class \_UIntType1 , \_UIntType1 \_\_a1, \_UIntType1 \_\_c1, \_UIntType1 \_\_m1, typename \_CharT , typename \_Traits \> std::basic\_istream\<\_CharT, \_Traits\>& operator\>\> (std::basic\_istream\< \_CharT, \_Traits \> &\_\_is, linear\_congruential\< \_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** random number generator.

**Returns:**

\_\_is.

## Member Data Documentation

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> const \_UIntType std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::increment` [static]`

An increment.

Definition at line 358 of file tr1\_impl/random.

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> const \_UIntType std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::modulus` [static]`

The modulus.

Definition at line 360 of file tr1\_impl/random.

### template\<class \_UIntType, \_UIntType \_\_a, \_UIntType \_\_c, \_UIntType \_\_m\> const \_UIntType std::linear\_congruential\< \_UIntType, \_\_a, \_\_c, \_\_m \>::multiplier` [static]`

The multiplier.

Definition at line 356 of file tr1\_impl/random.

## Author

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