thrust::random::subtract_with_carry_engine

Defined in thrust/random/subtract_with_carry_engine.h

template<typename UIntType, size_t w, size_t s, size_t r>
class subtract_with_carry_engine

A subtract_with_carry_engine random number engine produces unsigned integer random numbers using the subtract with carry algorithm of Marsaglia & Zaman.

The generation algorithm is performed as follows:

  1. Let Y = X_{i-s}- X_{i-r} - c.

  2. Set X_i to y = T mod m. Set c to 1 if Y < 0, otherwise set c to 0.

This algorithm corresponds to a modular linear function of the form

TA(x_i) = (a * x_i) mod b, where b is of the form m^r - m^s + 1 and a = b - (b-1)/m.

Note

Inexperienced users should not use this class template directly. Instead, use ranlux24_base or ranlux48_base, which are instances of subtract_with_carry_engine.

Template Parameters
  • UIntType – The type of unsigned integer to produce.

  • w – The word size of the produced values ( w <= sizeof(UIntType)).

  • s – The short lag of the generation algorithm.

  • r – The long lag of the generation algorithm.

Public Types

typedef UIntType result_type

The type of the unsigned integer produced by this subtract_with_carry_engine.

Public Functions

explicit subtract_with_carry_engine(result_type value = default_seed)

This constructor, which optionally accepts a seed, initializes a new subtract_with_carry_engine.

Parameters

value – The seed used to intialize this subtract_with_carry_engine's state.

void seed(result_type value = default_seed)

This method initializes this subtract_with_carry_engine's state, and optionally accepts a seed value.

Parameters

value – The seed used to initializes this subtract_with_carry_engine's state.

result_type operator()(void)

This member function produces a new random value and updates this subtract_with_carry_engine's state.

Returns

A new random number.

void discard(unsigned long long z)

This member function advances this subtract_with_carry_engine's state a given number of times and discards the results.

Note

This function is provided because an implementation may be able to accelerate it.

Parameters

z – The number of random values to discard.

Public Static Attributes

static const size_t word_size = w

The word size of the produced values.

static const size_t short_lag = s

The size of the short lag used in the generation algorithm.

static const size_t long_lag = r

The size of the long lag used in the generation algorithm.

static const result_type min = 0

The smallest value this subtract_with_carry_engine may potentially produce.

static const result_type max = modulus - 1

The largest value this subtract_with_carry_engine may potentially produce.

static const result_type default_seed = 19780503u

The default seed of this subtract_with_carry_engine.