Template Function thrust::generate_n(OutputIterator, Size, Generator)¶
Function Documentation¶
-
template<typename
OutputIterator
, typenameSize
, typenameGenerator
>
OutputIteratorthrust
::
generate_n
(OutputIterator first, Size n, Generator gen) generate_n
assigns the result of invokinggen
, a function object that takes no arguments, to each element in the range[first,first + n)
. The return value isfirst + n
.The following code snippet demonstrates how to fill a
host_vector
with random numbers, using the standard C library functionrand
.- Parameters
first
: The first element in the range of interest.n
: The size of the range of interest.gen
: A function argument, taking no parameters, used to generate values to assign to elements in the range[first,first + n)
.
- Template Parameters
OutputIterator
: is a model of Output Iterator.Size
: is an integral type (either signed or unsigned).Generator
: is a model of Generator, andGenerator's
result_type
is convertible to a type inOutputIterator's
set ofvalue_types
.
#include <thrust/generate.h> #include <thrust/host_vector.h> #include <stdlib.h> ... thrust::host_vector<int> v(10); srand(13); thrust::generate_n(v.begin(), 10, rand); // the elements of v are now pseudo-random numbers
- See
generate
- See