Class thrust::random::discard_block_engine

A discard_block_engine adapts an existing base random number engine and produces random values by discarding some of the values returned by its base engine. Each cycle of the compound engine begins by returning r values successively produced by the base engine and ends by discarding p-r such values. The engine’s state is the state of its base engine followed by the number of calls to operator() that have occurred since the beginning of the current cycle.

The following code snippet shows an example of using a discard_block_engine instance:

#include <thrust/random/linear_congruential_engine.h>
#include <thrust/random/discard_block_engine.h>
#include <iostream>

int main()
{
  // create a discard_block_engine from minstd_rand, with a cycle length of 13
  // keep every first 10 values, and discard the next 3
  thrust::discard_block_engine<thrust::minstd_rand, 13, 10> rng;

  // print a random number to standard output
  std::cout << rng() << std::endl;

  return 0;
}

Template Parameters:

  • Engine The type of the base random number engine to adapt.
  • p The discard cycle length.
  • r The number of values to return of the base engine. Because p-r will be discarded, r <= p.

#include <thrust/random/discard_block_engine.h>
template <typename Engine,   size_t p,   size_t r> class thrust::random::discard_block_engine { public:   /* The type of the adapted base random number engine. */  typedef see below base_type;
   /* The type of the unsigned integer produced by this linear_congruential_engine. */  typedef see below result_type;
  static const size_t block_size = see below;
  static const size_t used_block = see below;
  static const result_type min = see below;
  static const result_type max = see below;
  _CCCL_HOST_DEVICE   discard_block_engine();
  explicit _CCCL_HOST_DEVICE   discard_block_engine(const base_type & urng);
  explicit _CCCL_HOST_DEVICE   discard_block_engine(result_type s);
  _CCCL_HOST_DEVICE void   seed();
  _CCCL_HOST_DEVICE void   seed(result_type s);
  _CCCL_HOST_DEVICE result_type   operator()(void);
  _CCCL_HOST_DEVICE void   discard(unsigned long long z);
  _CCCL_HOST_DEVICE const base_type &   base() const; };

Member Types

Typedef thrust::random::discard_block_engine::base_type

typedef Enginebase_type; The type of the adapted base random number engine.

Typedef thrust::random::discard_block_engine::result_type

typedef base_type::result_typeresult_type; The type of the unsigned integer produced by this linear_congruential_engine.

Member Variables

Variable thrust::random::discard_block_engine::block_size

static const size_t block_size = p; The length of the production cycle.

Variable thrust::random::discard_block_engine::used_block

static const size_t used_block = r; The number of used numbers per production cycle.

Variable thrust::random::discard_block_engine::min

static const result_type min = base_type::min; The smallest value this discard_block_engine may potentially produce.

Variable thrust::random::discard_block_engine::max

static const result_type max = base_type::max; The largest value this discard_block_engine may potentially produce.

Member Functions

Function thrust::random::discard_block_engine::discard_block_engine

_CCCL_HOST_DEVICE discard_block_engine(); This constructor constructs a new discard_block_engine and constructs its base_type engine using its null constructor.

Function thrust::random::discard_block_engine::discard_block_engine

explicit _CCCL_HOST_DEVICE discard_block_engine(const base_type & urng); This constructor constructs a new discard_block_engine using a given base_type engine to initialize its adapted base engine.

Function Parameters: urng: A base_type to use to initialize this discard_block_engine's adapted base engine.

Function thrust::random::discard_block_engine::discard_block_engine

explicit _CCCL_HOST_DEVICE discard_block_engine(result_type s); This constructor initializes a new discard_block_engine with a given seed.

Function Parameters: s: The seed used to intialize this discard_block_engine's adapted base engine.

Function thrust::random::discard_block_engine::seed

_CCCL_HOST_DEVICE void seed(); This method initializes the state of this discard_block_engine's adapted base engine by using its default_seed value.

Function thrust::random::discard_block_engine::seed

_CCCL_HOST_DEVICE void seed(result_type s); This method initializes the state of this discard_block_engine's adapted base engine by using the given seed.

Function Parameters: s: The seed with which to intialize this discard_block_engine's adapted base engine.

Function thrust::random::discard_block_engine::operator()

_CCCL_HOST_DEVICE result_type operator()(void); This member function produces a new random value and updates this discard_block_engine's state.

Returns: A new random number.

Function thrust::random::discard_block_engine::discard

_CCCL_HOST_DEVICE void discard(unsigned long long z); This member function advances this discard_block_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.

Function thrust::random::discard_block_engine::base

_CCCL_HOST_DEVICE const base_type & base() const; This member function returns a const reference to this discard_block_engine's adapted base engine.

Returns: A const reference to the base engine this discard_block_engine adapts.