Created
October 31, 2013 06:20
-
-
Save ashwin/7245048 to your computer and use it in GitHub Desktop.
How to generate random numbers using Thrust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <thrust/device_vector.h> | |
#include <thrust/random.h> | |
struct GenRand | |
{ | |
__device__ | |
float operator () (int idx) | |
{ | |
thrust::default_random_engine randEng; | |
thrust::uniform_real_distribution<float> uniDist; | |
randEng.discard(idx); | |
return uniDist(randEng); | |
} | |
}; | |
const int randNum = 1000; // Size of vector | |
thrust::device_vector<float> rVec(randNum); | |
thrust::transform( | |
thrust::make_counting_iterator(0), | |
thrust::make_counting_iterator(randNum), | |
rVec.begin(), | |
GenRand()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment