thrust

◆ generate() [1/2]

template<typename DerivedPolicy , typename ForwardIterator , typename Generator >
__host__ __device__ void thrust::generate ( const thrust::detail::execution_policy_base< DerivedPolicy > &  exec,
ForwardIterator  first,
ForwardIterator  last,
Generator  gen 
)

generate assigns the result of invoking gen, a function object that takes no arguments, to each element in the range [first,last).

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

Parameters
execThe execution policy to use for parallelization.
firstThe first element in the range of interest.
lastThe last element in the range of interest.
genA function argument, taking no parameters, used to generate values to assign to elements in the range [first,last).
Template Parameters
DerivedPolicyThe name of the derived execution policy.
ForwardIteratoris a model of Forward Iterator, and ForwardIterator is mutable.
Generatoris a model of Generator, and Generator's result_type is convertible to ForwardIterator's value_type.

The following code snippet demonstrates how to fill a host_vector with random numbers, using the standard C library function rand using the thrust::host execution policy for parallelization:

#include <cstdlib>
...
thrust::host_vector<int> v(10);
srand(13);
thrust::generate(thrust::host, v.begin(), v.end(), rand);
// the elements of v are now pseudo-random numbers
See also
generate_n
http://www.sgi.com/tech/stl/generate.html