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:
Let
Y = X_{i-s}- X_{i-r} - c
.Set
X_i
toy = T mod m
. Setc
to1
ifY < 0
, otherwise setc
to0
.
This algorithm corresponds to a modular linear function of the form
TA(x_i) = (a * x_i) mod b
, whereb
is of the formm^r - m^s + 1
anda = b - (b-1)/m
.See also
See also
Note
Inexperienced users should not use this class template directly. Instead, use
ranlux24_base
orranlux48_base
, which are instances ofsubtract_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 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
.