Boost logo

Boost :

Subject: Re: [boost] Problem with boost::random seed
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-01-28 00:12:21


AMDG

On 1/27/2011 7:10 PM, Anton Skvorts wrote:
> Oh, although the code was run with just one variate_generator, I
> transcribed in my post one line of the code erroneously:
>
> where is die(gen, normal) it should be rng(gen, normal)
>
> Anyway I got that strange output using just one variate_generator everywhere:
> variate_generator<std::mt19937&,std::normal_distribution<> > rng(gen, normal);
>
> Steven, does your comment still applies in this case?
>

I can't reproduce your problem. Here's the code I tested with

#include <boost/random/mersenne_twister.hpp>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/variate_generator.hpp>
#include <iostream>

using namespace std;

template<class G, class T>
void reseed(G& gen, const T& t) {
     gen.engine().seed(t);
     gen.distribution().reset();
}

int main() {
     boost::mt19937 gen;
     boost::normal_distribution<> normal(0,1);
     boost::variate_generator<
         boost::mt19937 &,
         boost::normal_distribution<> > rng(gen, normal);
     cout << rng() << endl;
     cout << rng() << endl;
     cout << rng() << endl;
     reseed(rng, 0);
     cout << rng() << endl;
     cout << rng() << endl;
     cout << rng() << endl;
     cout << rng() << endl;
     reseed(rng, 1);
     cout << rng() << endl;
     cout << rng() << endl;
     cout << rng() << endl;
     cout << rng() << endl;
}

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk