---
name: "std::tr1::subtract_with_carry"
section: "3"
platform: "linux"
package: "libstdc++6-4.2-doc"
version: "4.2.4-6"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/std::tr1::subtract_with_carry"
---

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

## NAME

std::tr1::subtract\_with\_carry -

## SYNOPSIS

## Detailed Description

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> class std::tr1::subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \>

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 $x\_{i}

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

N1688\[4.13\] says 'the template parameter \_IntType shall denote an integral type large enough to store values up to m.'

Definition at line 668 of file random.

### Public Types

typedef \_IntType **result\_type**\

### Public Member Functions

**result\_type** **max** () const \
 **result\_type** **min** () const \
 **result\_type** **operator()** ()\
 template\<class \_Gen\> void **seed** (\_Gen &\_\_g)\
 void **seed** (unsigned long \_\_value=19780503)\
 template\<class \_Gen\> **subtract\_with\_carry** (\_Gen &\_\_g)\
 **subtract\_with\_carry** (unsigned long \_\_value)\
 **subtract\_with\_carry** ()\

### Static Public Attributes

static const int **long\_lag**\
 static const \_IntType **modulus**\
 static const int **short\_lag**\

### Friends

bool **operator!=** (const **subtract\_with\_carry** &\_\_lhs, const **subtract\_with\_carry** &\_\_rhs)\
 template\<typename \_IntType1, \_IntType1 \_\_m1, int \_\_s1, int \_\_r1, typename \_CharT, typename \_Traits\> **std::basic\_ostream**\< \_CharT, \_Traits \> & **operator\<\<** (**std::basic\_ostream**\< \_CharT, \_Traits \> &\_\_os, const **subtract\_with\_carry**\< \_IntType1, \_\_m1, \_\_s1, \_\_r1 \> &\_\_x)\
 bool **operator==** (const **subtract\_with\_carry** &\_\_lhs, const **subtract\_with\_carry** &\_\_rhs)\
 template\<typename \_IntType1, \_IntType1 \_\_m1, int \_\_s1, int \_\_r1, typename \_CharT, typename \_Traits\> **std::basic\_istream**\< \_CharT, \_Traits \> & **operator\>\>** (**std::basic\_istream**\< \_CharT, \_Traits \> &\_\_is, **subtract\_with\_carry**\< \_IntType1, \_\_m1, \_\_s1, \_\_r1 \> &\_\_x)\

## Member Typedef Documentation

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> typedef \_IntType std::tr1::subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \>::result\_type

The type of the generated random value.

Definition at line 674 of file random.

## Constructor & Destructor Documentation

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> std::tr1::subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \>::subtract\_with\_carry ()` [inline]`

Constructs a default-initialized % **subtract\_with\_carry** random number generator.

Definition at line 685 of file random.

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> std::tr1::subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \>::subtract\_with\_carry (unsigned long \_\_value)` [inline, explicit]`

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

Definition at line 693 of file random.

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> template\<class \_Gen\> std::tr1::subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \>::subtract\_with\_carry (\_Gen & \_\_g)` [inline]`

Constructs a subtract\_with\_carry random number generator engine seeded from the generator function `__g`.

**Parameters:**

*\_\_g* The seed generator function.

Definition at line 703 of file random.

## Member Function Documentation

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> result\_type std::tr1::subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \>::max () const` [inline]`

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

Definition at line 742 of file random.

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> result\_type std::tr1::subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \>::min () const` [inline]`

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

Definition at line 734 of file random.

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \>::result\_type std::tr1::subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \>::operator() ()` [inline]`

Gets the next random number in the sequence.

Definition at line 362 of file random.tcc.

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> template\<class \_Gen\> void std::tr1::subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \>::seed (\_Gen & \_\_g)` [inline]`

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

Definition at line 726 of file random.

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> void std::tr1::subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \>::seed (unsigned long \_\_value = `19780503`)` [inline]`

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.

Definition at line 320 of file random.tcc.

## Friends And Related Function Documentation

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> bool operator!= (const subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \> & \_\_lhs, const subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \> & \_\_rhs)` [friend]`

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

**Parameters:**

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

**Returns:**

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

Definition at line 777 of file random.

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> template\<typename \_IntType1, \_IntType1 \_\_m1, int \_\_s1, int \_\_r1, typename \_CharT, typename \_Traits\> std::basic\_ostream\<\_CharT, \_Traits\>& operator\<\< (std::basic\_ostream\< \_CharT, \_Traits \> & \_\_os, const subtract\_with\_carry\< \_IntType1, \_\_m1, \_\_s1, \_\_r1 \> & \_\_x)` [friend]`

Inserts the current state of a % **subtract\_with\_carry** random number generator engine `__x` into the output stream `__os`.

**Parameters:**

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

**Returns:**

The output stream with the state of `__x` inserted or in an error state.

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> bool operator== (const subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \> & \_\_lhs, const subtract\_with\_carry\< \_IntType, \_\_m, \_\_s, \_\_r \> & \_\_rhs)` [friend]`

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

**Parameters:**

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

**Returns:**

true if the two objects are equal, false otherwise.

Definition at line 762 of file random.

### template\<typename \_IntType, \_IntType \_\_m, int \_\_s, int \_\_r\> template\<typename \_IntType1, \_IntType1 \_\_m1, int \_\_s1, int \_\_r1, typename \_CharT, typename \_Traits\> std::basic\_istream\<\_CharT, \_Traits\>& operator\>\> (std::basic\_istream\< \_CharT, \_Traits \> & \_\_is, subtract\_with\_carry\< \_IntType1, \_\_m1, \_\_s1, \_\_r1 \> & \_\_x)` [friend]`

Extracts the current state of a % **subtract\_with\_carry** random number generator engine `__x` from the input stream `__is`.

**Parameters:**

*\_\_is* An input stream. \
 *\_\_x* A % **subtract\_with\_carry** 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.
