Boost logo

Boost Users :

Subject: Re: [Boost-users] [Math/Statistical Distributions+Random] Random number generation
From: er (erwann.rogard_at_[hidden])
Date: 2009-04-17 15:24:49


Maybe automate the stated requirement?

(not tested):

template<typename D>
struct math_to_random{};

template<typename T,typename P>
struct math_to_random<math::exponential_distribution<T,P> >{
   typedef exponential_distribution<T> type;
};

etc.

template<typename G,typename T,typename P>
variate_generator<
  G&,
  math_to_random<math::exponential_distribution<T,P> >::type
>
make_variate_generator(
  G& rng,
  const math::exponential_distribution<T,P>& dist0
){
   typedef typename math_to_random<exponential_distribution<T,P> >::type
rd_t;
   typename variate_generator<
  G&,
  rd_t
> vg_t;

   rd_t rd(dist0.lambda());
   return vg_t(rng,dist)
}

etc.

Usage:

... gen;
... vec;
math::exponential_distribution<T,P> dist(lambda);

std::generate_n(
  back_inserter(vec),
  n,
  make_variate_generator(rng,dist)
)


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net