---
name: "std::subtract_with_carry_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::subtract_with_carry_engine"
---

# std::subtract\_with\_carry\_engine(3)

The Marsaglia-Zaman generator.

## NAME

std::subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \> - The Marsaglia-Zaman generator.

## SYNOPSIS

\#include \<random\>

### Public Types

typedef \_UIntType **result\_type**\

### Public Member Functions

template\<typename \_Sseq, typename = \_If\_seed\_seq\<\_Sseq\>\> **subtract\_with\_carry\_engine** (\_Sseq &\_\_q)\
 Constructs a subtract\_with\_carry\_engine random number engine seeded from the seed sequence \_\_q.  **subtract\_with\_carry\_engine** (**result\_type** \_\_sd)\
 Constructs an explicitly seeded subtract\_with\_carry\_engine random number generator.  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)\
 Seeds the initial state $x\_0$ of the % subtract\_with\_carry\_engine random number generator.  void **seed** (**result\_type** \_\_sd=0u)\
 Seeds the initial state $x\_0$ of the random number generator.

### Static Public Member Functions

static constexpr **result\_type** **max** ()\
 Gets the inclusive maximum value of the range of random integers returned by this generator.  static constexpr **result\_type** **min** ()\
 Gets the inclusive minimum value of the range of random integers returned by this generator.

### Static Public Attributes

static constexpr uint\_least32\_t **default\_seed**\
 static constexpr size\_t **long\_lag**\
 static constexpr size\_t **short\_lag**\
 static constexpr size\_t **word\_size**\

### Friends

template\<typename \_UIntType1, size\_t \_\_w1, size\_t \_\_s1, size\_t \_\_r1, typename \_CharT, typename \_Traits\> **std::basic\_ostream**\< \_CharT, \_Traits \> & **operator\<\<** (**std::basic\_ostream**\< \_CharT, \_Traits \> &\_\_os, const **std::subtract\_with\_carry\_engine**\< \_UIntType1, \_\_w1, \_\_s1, \_\_r1 \> &\_\_x)\
 Inserts the current state of a % subtract\_with\_carry\_engine random number generator engine \_\_x into the output stream \_\_os.  bool **operator==** (const subtract\_with\_carry\_engine &\_\_lhs, const subtract\_with\_carry\_engine &\_\_rhs)\
 Compares two % subtract\_with\_carry\_engine random number generator objects of the same type for equality.  template\<typename \_UIntType1, size\_t \_\_w1, size\_t \_\_s1, size\_t \_\_r1, typename \_CharT, typename \_Traits\> **std::basic\_istream**\< \_CharT, \_Traits \> & **operator\>\>** (**std::basic\_istream**\< \_CharT, \_Traits \> &\_\_is, **std::subtract\_with\_carry\_engine**\< \_UIntType1, \_\_w1, \_\_s1, \_\_r1 \> &\_\_x)\
 Extracts the current state of a % subtract\_with\_carry\_engine random number generator engine \_\_x from the input stream \_\_is.

## Detailed Description

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\>

class std::subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \>"The Marsaglia-Zaman generator.

This is a model of a Generalized Fibonacci discrete random number generator, sometimes referred to as the SWC generator.

A discrete random number generator that produces pseudorandom numbers using:    \]

The size of the state is $r$ and the maximum period of the generator is $(m^r - m^s - 1)$.

**Since**

C++11

## Member Typedef Documentation

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> typedef \_UIntType std::subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \>::result\_type

The type of the generated random value.

## Constructor & Destructor Documentation

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> std::subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \>::subtract\_with\_carry\_engine (result\_type \_\_sd) \[inline\], \[explicit\]

Constructs an explicitly seeded subtract\_with\_carry\_engine random number generator.

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> template\<typename \_Sseq, typename = \_If\_seed\_seq\<\_Sseq\>\> std::subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \>::subtract\_with\_carry\_engine (\_Sseq & \_\_q) \[inline\], \[explicit\]

Constructs a subtract\_with\_carry\_engine random number engine seeded from the seed sequence \_\_q.

**Parameters**

*\_\_q* the seed sequence.

## Member Function Documentation

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> void std::subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \>::discard (unsigned long long \_\_z) \[inline\]

Discard a sequence of random numbers.

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> constexpr result\_type std::subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \>::max () \[inline\], \[static\], \[constexpr\]

Gets the inclusive maximum value of the range of random integers returned by this generator.

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> constexpr result\_type std::subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \>::min () \[inline\], \[static\], \[constexpr\]

Gets the inclusive minimum value of the range of random integers returned by this generator.

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \>::result\_type std::subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \>::operator() ()

Gets the next random number in the sequence.

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> template\<typename \_Sseq\> auto std::subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \>::seed (\_Sseq & \_\_q) -\> \_If\_seed\_seq\< \_Sseq \>

Seeds the initial state $x\_0$ of the % subtract\_with\_carry\_engine random number generator.

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> void std::subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \>::seed (result\_type \_\_sd = 0u)

Seeds the initial state $x\_0$ of the random number generator. N1688\[4.19\] modifies this as follows. If \_\_value == 0, sets value to 19780503. In any case, with a linear congruential generator lcg(i) having parameters   $ m\_{lcg} = 2147483563, a\_{lcg} = 40014, c\_{lcg} = 0, and lcg(0) = value $, sets $ x\_{-r} ots x\_{-1} $ to  $ lcg(1)  ots lcg(r)  $ respectively. If $ x\_{-1} = 0 $ set carry to 1, otherwise sets carry to 0.

Referenced by **std::subtract\_with\_carry\_engine\< uint\_fast32\_t, 24, 10, 24 \>::subtract\_with\_carry\_engine()**, and **std::subtract\_with\_carry\_engine\< uint\_fast32\_t, 24, 10, 24 \>::subtract\_with\_carry\_engine()**.

## Friends And Related Symbol Documentation

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> template\<typename \_UIntType1, size\_t \_\_w1, size\_t \_\_s1, size\_t \_\_r1, typename \_CharT, typename \_Traits\> std::basic\_ostream\< \_CharT, \_Traits \> & operator\<\< (std::basic\_ostream\< \_CharT, \_Traits \> & \_\_os, const std::subtract\_with\_carry\_engine\< \_UIntType1, \_\_w1, \_\_s1, \_\_r1 \> & \_\_x) \[friend\]

Inserts the current state of a % subtract\_with\_carry\_engine random number generator engine \_\_x into the output stream \_\_os.

**Parameters**

*\_\_os* An output stream. \
 *\_\_x* A % subtract\_with\_carry\_engine random number generator engine.

**Returns**

The output stream with the state of \_\_x inserted or in an error state.

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> bool operator== (const subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \> & \_\_lhs, const subtract\_with\_carry\_engine\< \_UIntType, \_\_w, \_\_s, \_\_r \> & \_\_rhs) \[friend\]

Compares two % subtract\_with\_carry\_engine random number generator objects of the same type for equality.

**Parameters**

*\_\_lhs* A % subtract\_with\_carry\_engine random number generator object. \
 *\_\_rhs* Another % subtract\_with\_carry\_engine random number generator object.

**Returns**

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

### template\<typename \_UIntType, size\_t \_\_w, size\_t \_\_s, size\_t \_\_r\> template\<typename \_UIntType1, size\_t \_\_w1, size\_t \_\_s1, size\_t \_\_r1, typename \_CharT, typename \_Traits\> std::basic\_istream\< \_CharT, \_Traits \> & operator\>\> (std::basic\_istream\< \_CharT, \_Traits \> & \_\_is, std::subtract\_with\_carry\_engine\< \_UIntType1, \_\_w1, \_\_s1, \_\_r1 \> & \_\_x) \[friend\]

Extracts the current state of a % subtract\_with\_carry\_engine random number generator engine \_\_x from the input stream \_\_is.

**Parameters**

*\_\_is* An input stream. \
 *\_\_x* A % subtract\_with\_carry\_engine random number generator engine.

**Returns**

The input stream with the state of \_\_x extracted or in an error state.

## Author

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