Boost logo

Boost Users :

Subject: Re: [Boost-users] [Math/Statistical Distributions+Random] Random numbergeneration
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 2009-04-18 06:59:48


On Sat, Apr 18, 2009 at 10:50 AM, John Maddock <john_at_[hidden]> wrote:
>> Well, what is the rationale behind the choice of this separation?
>
> We haven't had time to provide it yet :-(
>
>> Do you think would be useful to provide this kind of integration?
>
> Yes for sure.
>

Cool!
Time is short also for me.
However maybe I can help you in writing it

Note:
I'm not an expert in metaprogramming, neither in boost library; so I
don't want to become a bottleneck for library release.

A possible solution might be:
--- [snip] ---
template<typename G,typename T,typename P>
T rand(G& rng, const boost::math::exponential_distribution<T,P>& dist)
{
    typedef typename boost::exponential_distribution<T> rdist_type;
    typedef typename boost::variate_generator<G&,rdist_type> variate_type;

    return variate_type(rng, rdist_type(dist.lambda()))();
}
--- [/snip] ---
This is not the *best* solution since each time rand is called a
temporary boost::variate_generator and boost::exponential_distribution
objects are created.
Another possible solution is to copy the code from the
math/random/*.hpp classes although this duplication is not so good.

Further in some case we have to move the implemention inside the
(math::) distribution for keeping a kind of state (e.g., the normal
variate generation include the generation of two uniform numbers at
time) and the call this method from the rand function, like this
below:
--- [snip] ---
template<typename G,typename T,typename P>
T rand(G& rng, const boost::math::normal_distribution<T,P>& dist)
{
    return dist.rand(rng);
}
--- [/snip] ---

Let me know.

-- Marco

> HTH, John.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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