jeudi 19 mars 2015

Randomly Generated Numbers from Boost Pareto Distribution

So I did a fair amount of looking around stack overflow and google before asking this question. I have a simulation that I am working on and need to be able to generate random input data between 0 and 1.0 that follow certain statistical distributions.


So far, I have gotten a normal distribution and a uniform real distribution working properly, but am stuck with the Pareto distribution.


The first two are available in boost/random/, but the pareto is not. Does anyone know of a way to generate said random numbers?


Any help would be greatly appreciated as I am new to boost.


Thank you!


Here is the code I am using for the first two, in tandem with a variant generator. This is all very much test code, so please don't hammer me on style or conventions:



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

int main(){
boost::mt19937 randGen(time(0));

boost::normal_distribution<> dist1(.5,.2);
boost::random::uniform_real_distribution<> dist2(0.0,1.0);

boost::variate_generator<boost::mt19937&,boost::normal_distribution<> > generator1(randGen,dist1);
boost::variate_generator<boost::mt19937&,boost::random::uniform_real_distribution<> > generator2(randGen,dist2);

for(int x = 0; x < 10; x++)
std::cout << generator1() << std::endl;

std::cout << "\n\n\n";

for(int x = 0; x < 10; x++)
std::cout << generator2() << std::endl;

return 0;
}

Aucun commentaire:

Enregistrer un commentaire