Boost logo

Boost Users :

Subject: [Boost-users] [Random] Passing an arbitrary uniform random number generator to a function
From: Joseph Wakeling (joseph.wakeling_at_[hidden])
Date: 2010-04-26 13:43:32


Hello,

Suppose that I have a function that takes a uniform random number
generator as an argument, e.g.

    double foo(mt19937 &urng)
    {
        double x = uniform_real<double> (0.0, 10.0) (urng);
        double y = uniform_real<double> (5.0, 7.0) (urng);

        return (x*y);
    }

Is there a way to make the choice of random number generator arbitrary
(i.e. not limited to mt19937) without making the function a template?
Alternatively, is there a better way of passing around the basic uniform
random number generator?

The reason for the no-template rule is that I would like to pass a URNG
to a virtual function in a class, and I would really not like to have to
make the class itself a template dependent on the type of URNG.

Can someone recommend a solution?

Thanks and best wishes,

    -- Joe


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