Boost logo

Boost Users :

From: Michael Fuller (mm.fuller_at_[hidden])
Date: 2008-07-16 12:41:25


John Maddock <john <at> johnmaddock.co.uk> writes:
> Um, argument to the quantile function surely?

Oops, yes, the quantile function.

I eventually found what I was looking for in some code written by
Joaquín M López Muñoz.

For the sake of closure, here is an example:

//Generate a Poisson-distributed random variate given a
//specific mean value):

#include <boost/random.hpp>
#include <boost/random/poisson_distribution.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int.hpp>
#include <boost/random/uniform_smallint.hpp>
#include <iostream>

using namespace std;
using namespace boost::random;

int main()
{
        double lambda(10); //mean of Poisson distr
         boost::mt19937 rnd_gen; //Mersenne Twister generator

          typedef boost::variate_generator<
               boost::mt19937, boost::poisson_distribution<>
> rnd_poisson_t;

          rnd_poisson_t rnd_poisson( rnd_gen,
                boost::poisson_distribution<>( lambda ));

        rnd_poisson = rnd_poisson_t( rnd_gen,
                boost::poisson_distribution<>( lambda ));

        cout << "\nFive Poisson-distributed random numbers\n";
        for(int i = 0; i < 5; i++) {
                cout << rnd_poisson() << endl;
        }
        
            return 0;
}


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