thrust::shuffle

Defined in thrust/shuffle.h

template<typename RandomIterator, typename URBG>
void thrust::shuffle(RandomIterator first, RandomIterator last, URBG &&g)

shuffle reorders the elements [first, last) by a uniform pseudorandom permutation, defined by random engine g.

The following code snippet demonstrates how to use shuffle to create a random permutation.

#include <thrust/shuffle.h>
#include <thrust/random.h>
int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const int N = sizeof(A)/sizeof(int);
thrust::default_random_engine g;
thrust::shuffle(A, A + N, g);
// A is now {6, 5, 8, 7, 2, 1, 4, 3, 10, 9}

See also

shuffle_copy

Parameters
  • first – The beginning of the sequence to shuffle.

  • last – The end of the sequence to shuffle.

  • g – A UniformRandomBitGenerator

Template Parameters
  • RandomIterator – is a random access iterator

  • URBG – is a uniform random bit generator