I have a function object for parallelizing a for_each() algorithm using Thread Building Blocks,
The function object uses a random number generator RND whose operator method () generates a random number.
Problem: I need a random number number generator to 1) initialize only once in the function object 2) should be threadsafe and 3) can be provided same seed so that same results could be obtained.
I dont know much about generating thread safe random number generators in function objects as such. I tried using my own random generator class (using engine, distribution and generators) (using boost libraries) but I need something simple such as erand() ? or something like that for which we dont need to do write separate code.
struct func {
public:
func() { }
func(int t_) : t(t_) { }
template <typename house_t>
void operator()(house_t house) const {
if ( RND() )
{ //do something with the house }
} //operator
private:
int t;
};
//Parallel for_each
tbb::parallel_for_each( house.begin(), house.end(), func(t) );
Please suggest