
2 May
2014
2 May
'14
12:32 p.m.
Thijs van den Berg wrote:
In that case it’s best to use a random engine adaptor.
counter_based_engine< Threefry<2,unsigned> > eng; uniform_real_distribution<float> zero_one(0., 1.);
eng.seed(thread_id);
for(int i=0; i<n; ++i) { out[i] = in[i]*zero_one( eng ); }
The adaptor needs to be in the loop; you don't have a thread_id outside it. uniform_real_distribution<float> zero_one(0., 1.); #pragma omp parallel for for( int i=0; i<n; ++i ) { counter_based_engine< Threefry<2,unsigned> > eng; eng.seed( i ); out[i] = in[i]*zero_one( eng ); } In principle, this works with any engine, not just a counter-based one, as long as creating and seeding is quick and consecutive seeds result in random first output.