thrust::random::xor_combine_engine

Defined in thrust/random/xor_combine_engine.h

template<typename Engine1, size_t s1, typename Engine2, size_t s2 = 0u>
class xor_combine_engine

An xor_combine_engine adapts two existing base random number engines and produces random values by combining the values produced by each.

The following code snippet shows an example of using an xor_combine_engine instance:

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

int main()
{
  // create an xor_combine_engine from minstd_rand and minstd_rand0
  // use a shift of 0 for each
  thrust::xor_combine_engine<thrust::minstd_rand,0,thrust::minstd_rand0,0> rng;

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

  return 0;
}

Template Parameters
  • Engine1 – The type of the first base random number engine to adapt.

  • s1 – The size of the first shift to use in the generation algorithm.

  • Engine2 – The type of the second base random number engine to adapt.

  • s2 – The second of the second shift to use in the generation algorithm. Defaults to 0.

Public Types

typedef Engine1 base1_type

The type of the first adapted base random number engine.

typedef Engine2 base2_type

The type of the second adapted base random number engine.

typedef typename thrust::detail::eval_if<(sizeof(typename base2_type::result_type) > sizeof(typename base1_type::result_type)), thrust::detail::identity_<typename base2_type::result_type>, thrust::detail::identity_<typename base1_type::result_type>>::type result_type

The type of the unsigned integer produced by this xor_combine_engine.

Public Functions

xor_combine_engine()

This constructor constructs a new xor_combine_engine and constructs its adapted engines using their null constructors.

xor_combine_engine(const base1_type &urng1, const base2_type &urng2)

This constructor constructs a new xor_combine_engine using given base1_type and base2_type engines to initialize its adapted base engines.

Parameters
  • urng1 – A base1_type to use to initialize this xor_combine_engine's first adapted base engine.

  • urng2 – A base2_type to use to initialize this xor_combine_engine's first adapted base engine.

xor_combine_engine(result_type s)

This constructor initializes a new xor_combine_engine with a given seed.

Parameters

s – The seed used to intialize this xor_combine_engine's adapted base engines.

void seed()

This method initializes the state of this xor_combine_engine's adapted base engines by using their default_seed values.

void seed(result_type s)

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

Parameters

s – The seed with which to intialize this xor_combine_engine's adapted base engines.

result_type operator()(void)

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

Returns

A new random number.

void discard(unsigned long long z)

This member function advances this xor_combine_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 base1_type &base1() const

This member function returns a const reference to this xor_combine_engine's first adapted base engine.

Returns

A const reference to the first base engine this xor_combine_engine adapts.

const base2_type &base2() const

This member function returns a const reference to this xor_combine_engine's second adapted base engine.

Returns

A const reference to the second base engine this xor_combine_engine adapts.

Public Static Attributes

static const size_t shift1 = s1

The size of the first shift used in the generation algorithm.

static const size_t shift2 = s2

The size of the second shift used in the generation algorithm.

static const result_type min = 0

The smallest value this xor_combine_engine may potentially produce.

static const result_type max = detail::xor_combine_engine_max<Engine1, s1, Engine2, s2, result_type>::value

The largest value this xor_combine_engine may potentially produce.