0

I need to create a number generator that draws numbers with a Pareto distribution in a specific interval. I am working in C++.

I cannot use the <random> lib of C++ 11 so I was trying to solve my problem by using the boost library where I found the class pareto_distribution.

There is another question about this topic but the solution they proposed does not work for me.

Can anyone help me ?

thanks in advance.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
DL_
  • 1
  • 2
    Show us what you did – Tommaso Bertoni Mar 08 '16 at 08:13
  • 2
    "but the solution they proposed does not work for me." - You didn't even link to it. So no one should waste time giving you an answer that will most likely "not work for you" for mysterious reasons. – sehe Mar 08 '16 at 08:28
  • Sorry, you are right. This is the link to the previous question I found : http://stackoverflow.com/questions/29155783/randomly-generated-numbers-from-boost-pareto-distribution?rq=1. I also attached my script that I wrote according to that solution with also the error. Thanks for your advice – DL_ Mar 08 '16 at 09:04
  • You can easily generate it from an exponential distribution : https://en.wikipedia.org/wiki/Pareto_distribution#Relation_to_the_exponential_distribution – Caduchon Mar 08 '16 at 09:28

1 Answers1

0

This is the script I wrote:

    #include <iostream> 
    #include <boost/random/uniform_real_distribution.hpp>
    #include <boost/random/mersenne_twister.hpp>
    #include <boost/random/variate_generator.hpp>
    #include <boost/math/distributions/pareto.hpp>
    #include <time.h>

using namespace std;

int main()
{

     boost::mt19937 *rg = new boost::mt19937();
     rg->seed(time(NULL));
     boost::math::pareto_distribution<> dist;
     boost::random::uniform_real_distribution<> uniformReal(1.0,10.0);

     boost::variate_generator<boost::mt19937&,boost::random::uniform_real_distribution<> > generator(rg, dist);

     double cdfComplement;
     cdfComplement = boost::math::complement::cdf(boost::math::complement(dist,generator()));

     cout << " cdfComplement: " << cdfComplement << endl;


     return 0;
}
DL_
  • 1
  • It gives me an error at this line: boost::variate_generator > generator(rg, dist); -- error: no matching function to call – DL_ Mar 08 '16 at 08:57