The problem is that all myVectors in all myClass' objects are filled with the same set of values.
That’s because std::vector<myClass>(20, myClass(no_of_inputs))
gets you 20 copies of one temporary object.
If you provide a default-ctor for myClass
you can skip the second parameter to the vector
-ctor.
You can also push_back
the myClass
-objects one after another.
Which brings us to suggestions:
I see your randomize::operator()
is marked __host__
, then there is no reason to use thrust::for_each
in favor of std::for_each
.
I cannot use c++11 (presently) or boost (at all)
But you can use the tr1-extensions, which also offer a <random>
-header:
#include <tr1/random>
template <typename T>
struct twisterize {
const T min;
const T max;
twisterize(const T & min, const T & max) : min(min), max(max) {}
void operator()(T & x) {
typedef std::tr1::mt19937 rng_t;
typedef std::tr1::uniform_real<T> dist_t;
static rng_t rng( ((std::tr1::random_device())) ());//most vexing parse, yikes
static dist_t dist(min, max);// [min,max) for real distributions
static std::tr1::variate_generator<rng_t, dist_t> bound_dist(rng, dist);//not necessary in c++11
x = bound_dist();//using the c++11 way `dist(rng)` produces unexpected results with tr1
}
};
Since the functor now has state, you better create a variable for it, and pass that to for_each
:
twisterize<double> rand_functor(-0.5, 0.5);
If you really want random numbers generated on the gpu look here