Boost logo

Boost :

Subject: Re: [boost] Problem with boost::random seed
From: Max (more4less_at_[hidden])
Date: 2011-02-09 08:50:48


Hello Steven,

I get the following from you code:

0.213436
-0.49558
1.57538
-1.27801
-0.404742
-0.418455
-1.88258
-2.97183
1.70695
-0.430499
-2.28202

Shouldn't they be in [0, 1]?

I'm using WinXP + VS2008.

Thanks
Max

> -----Original Message-----
> From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]]
> On Behalf Of Steven Watanabe
> Sent: Friday, January 28, 2011 1:12 PM
> To: boost_at_[hidden]
> Subject: Re: [boost] Problem with boost::random seed
>
> 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
> _______________________________________________
> Unsubscribe & other changes:
http://lists.boost.org/mailman/listinfo.cgi/boost


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