thrust::random::discard_block_engine

Defined in thrust/random/discard_block_engine.h

template<typename Engine, size_t p, size_t r>
class 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.

Public Types

typedef Engine base_type

The type of the adapted base random number engine.

typedef typename base_type::result_type result_type

The type of the unsigned integer produced by this linear_congruential_engine.

Public Functions

discard_block_engine()

This constructor constructs a new discard_block_engine and constructs its base_type engine using its null constructor.

explicit 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.

Parameters

urng – A base_type to use to initialize this discard_block_engine's adapted base engine.

explicit discard_block_engine(result_type s)

This constructor initializes a new discard_block_engine with a given seed.

Parameters

s – The seed used to intialize this discard_block_engine's adapted base engine.

void seed()

This method initializes the state of this discard_block_engine's adapted base engine by using its default_seed value.

void seed(result_type s)

This method initializes the state of this discard_block_engine's adapted base engine by using the given seed.

Parameters

s – The seed with which to intialize this discard_block_engine's adapted base engine.

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.

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.

Parameters

z – The number of random values to discard.

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.

Public Static Attributes

static const size_t block_size = p

The length of the production cycle.

static const size_t used_block = r

The number of used numbers per production cycle.

static const result_type min = base_type::min

The smallest value this discard_block_engine may potentially produce.

static const result_type max = base_type::max

The largest value this discard_block_engine may potentially produce.