Using the Beta distribution in a specific way

Hi everyone,

I needed to develop a C++ program, so I did the best I could (having no previous C++ experience). It required me to generate random numbers from a Normal distribution. I now need to modify it, preferably to work in a similar manner, for the Beta distribution. My original code goes like this:

1
2
3
4
5
6
7
8
9
#include <boost/random.hpp>

...main...

srand(time(NULL)) ;
seed = rand();
boost::mt19937 igen(seed) ;
boost::variate_generator<boost::mt19937, boost::normal_distribution<> >
norm_dist(igen, boost::normal_distribution<>(mu,sigma)) ;


However, the Beta distribution does not seem to be part of the "random" package in boost. It can be found as follows:
#include <boost/math/distributions/beta.hpp>
So when I try to marry up the two by doing:
1
2
3
4
5
srand(time(NULL)) ;
seed = rand();
boost::mt19937 igen(seed) ;
boost::variate_generator<boost::mt19937, boost::math::beta_distribution<> >
beta_dist(igen, boost::math::beta_distribution<>(2,2)) ;

...it does not work. I'm pretty sure I;m doing something conceptually wrong, but I don't have the core understanding of C++ coding to get it. Any help on how to get the Beta distribution working in the method given? If it's just not possible, what would be my best and simplest option that allows me to save my seed and gives easy access to the Beta distribution?

Any help much appreciated.:)
Last edited on
...anyone?
Yes that works, thank you. :) I was hoping for a solution along the lines of my initial code, but if not, oh well.
I just realised that there is a huge problem. Basically I need to generate (1,000,000)^2 numbers from this distribution. My program worked for 10-15 hours for other distributions such as exponential, normal, etc. A test run of my simulation showed that the Beta distribution will have to run for 25 days. The complexity of the Beta is a bit higher but it shouldn't account for that much. I can only think of two things that may be causing this:

1. The Beta distribution is much more complicated to simulate than the more well-known distributions.
2. The method from StackOverflow is inferior to the one I've been using.

Any thoughts?
Topic archived. No new replies allowed.