Class thrust::random::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
, 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.
See:
#include <thrust/random/subtract_with_carry_engine.h>
template <typename UIntType, size_t w, size_t s, size_t r> class thrust::random::subtract_with_carry_engine { public:
/* The type of the unsigned integer produced by this subtract_with_carry_engine
. */ typedef see below result_type;
static const size_t word_size = see below;
static const size_t short_lag = see below;
static const size_t long_lag = see below;
static const result_type min = see below;
static const result_type max = see below;
static const result_type default_seed = see below;
explicit _CCCL_HOST_DEVICE subtract_with_carry_engine(result_type value = default_seed) = default;
_CCCL_HOST_DEVICE void seed(result_type value = default_seed) = default;
_CCCL_HOST_DEVICE result_type operator()(void);
_CCCL_HOST_DEVICE void discard(unsigned long long z); };
Member Types
Typedef thrust::random::subtract_with_carry_engine::result_type
typedef UIntTyperesult_type;
The type of the unsigned integer produced by this subtract_with_carry_engine
.
Member Variables
Variable thrust::random::subtract_with_carry_engine::word_size
static const size_t word_size = w;
The word size of the produced values.
Variable thrust::random::subtract_with_carry_engine::short_lag
static const size_t short_lag = s;
The size of the short lag used in the generation algorithm.
Variable thrust::random::subtract_with_carry_engine::long_lag
static const size_t long_lag = r;
The size of the long lag used in the generation algorithm.
Variable thrust::random::subtract_with_carry_engine::min
static const result_type min = 0;
The smallest value this subtract_with_carry_engine
may potentially produce.
Variable thrust::random::subtract_with_carry_engine::max
static const result_type max = modulus - 1;
The largest value this subtract_with_carry_engine
may potentially produce.
Variable thrust::random::subtract_with_carry_engine::default_seed
static const result_type default_seed = 19780503u;
The default seed of this subtract_with_carry_engine
.
Member Functions
Function thrust::random::subtract_with_carry_engine::subtract_with_carry_engine
explicit _CCCL_HOST_DEVICE subtract_with_carry_engine(result_type value = default_seed) = default;
This constructor, which optionally accepts a seed, initializes a new subtract_with_carry_engine
.
Function Parameters: value
: The seed used to intialize this subtract_with_carry_engine's
state.
Function thrust::random::subtract_with_carry_engine::seed
_CCCL_HOST_DEVICE void seed(result_type value = default_seed) = default;
This method initializes this subtract_with_carry_engine's
state, and optionally accepts a seed value.
Function Parameters: value
: The seed used to initializes this subtract_with_carry_engine's
state.
Function thrust::random::subtract_with_carry_engine::operator()
_CCCL_HOST_DEVICE 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.
Function thrust::random::subtract_with_carry_engine::discard
_CCCL_HOST_DEVICE 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.
Function Parameters: z
: The number of random values to discard.