Thrust

◆ shuffle() [1/2]

template<typename DerivedPolicy , typename RandomIterator , typename URBG >
__host__ __device__ void thrust::shuffle ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
RandomIterator  first,
RandomIterator  last,
URBG &&  g 
)

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

The algorithm's execution is parallelized as determined by exec.

Parameters
execThe execution policy to use for parallelization.
firstThe beginning of the sequence to shuffle.
lastThe end of the sequence to shuffle.
gA UniformRandomBitGenerator
Template Parameters
DerivedPolicyThe name of the derived execution policy.
RandomIteratoris a random access iterator
URBGis a uniform random bit generator

The following code snippet demonstrates how to use shuffle to create a random permutation using the thrust::host execution policy for parallelization:

#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);
// A is now {6, 5, 8, 7, 2, 1, 4, 3, 10, 9}
See also
shuffle_copy