Boost logo

Boost :

Subject: Re: [boost] [random] new threefry random engine
From: Peter Dimov (lists_at_[hidden])
Date: 2014-05-02 08:32:37

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.

Boost list run by bdawes at, gregod at, cpdaniel at, john at