boost random question

For the new random number generators, if I want to share a single underlying uniform random generator, I need to do like so: typedef boost::mt19937 rng_t; rng_t rng; boost::variate_generator<rng_t&, boost::normal_distribution<> > tn (rng, boost::normal_distribution<> (0, sqrt (var))); boost::variate_generator<rng_t&, boost::pnseq_generator<1> > pn (rng, boost::pnseq_generator<1>()); That is, I need to say "rng_t&" for the 1st template param rather than "rng_t". Is this correct? The old rng lib passed the engine by ref in the constructor, but the new one doesn't. Correct?

Neal D. Becker wrote:
For the new random number generators, if I want to share a single underlying uniform random generator, I need to do like so:
typedef boost::mt19937 rng_t; rng_t rng; boost::variate_generator<rng_t&, boost::normal_distribution<> > tn (rng, boost::normal_distribution<> (0, sqrt (var))); boost::variate_generator<rng_t&, boost::pnseq_generator<1> > pn (rng, boost::pnseq_generator<1>());
That is, I need to say "rng_t&" for the 1st template param rather than "rng_t". Is this correct?
Yes.
The old rng lib passed the engine by ref in the constructor, but the new one doesn't. Correct?
No. The parameter in the constructor is what you put in the first template parameter. In your particular case, "rng" is passed by reference. (Btw, try "rng_t*" if you want to pass a pointer.) Jens Maurer
participants (2)
-
Jens Maurer
-
Neal D. Becker