📅 2013-Oct-31 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ random number generation, thrust ⬩ 📚 Archive
Thrust has support for many random number generator engines and distributions. For example, the code below generates floating point numbers in the uniform_real_distribution
using the default_random_engine
. By default, the numbers generated by the uniform real distribution are in the range [0.0, 1.0)
#include <thrust/device_vector.h>
#include <thrust/random.h>
struct GenRand
{
__device__float operator () (int idx)
{
thrust::default_random_engine randEng;float> uniDist;
thrust::uniform_real_distribution<
randEng.discard(idx);return uniDist(randEng);
}
};
const int randNum = 1000; // Size of vector
float> rVec(randNum);
thrust::device_vector<
thrust::transform(0),
thrust::make_counting_iterator(
thrust::make_counting_iterator(randNum),
rVec.begin(), GenRand());
Tried with: CUDA 5.5