◆ shuffle_copy() [2/2]

template<typename RandomIterator , typename OutputIterator , typename URBG >
__host__ __device__ void thrust::shuffle_copy ( RandomIterator  first,
RandomIterator  last,
OutputIterator  result,
URBG &&  g 

shuffle_copy differs from shuffle only in that the reordered sequence is written to different output sequences, rather than in place. shuffle_copy reorders the elements [first, last) by a uniform pseudorandom permutation, defined by random engine g.

firstThe beginning of the sequence to shuffle.
lastThe end of the sequence to shuffle.
resultDestination of shuffled sequence
gA UniformRandomBitGenerator
Template Parameters
RandomIteratoris a random access iterator
OutputIteratoris a model of Output Iterator.
URBGis a uniform random bit generator

The following code snippet demonstrates how to use shuffle_copy 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};
int result[10];
const int N = sizeof(A)/sizeof(int);
thrust::shuffle_copy(A, A + N, result, g);
// result is now {6, 5, 8, 7, 2, 1, 4, 3, 10, 9}
See also