Hi,
This is probably a silly question, but I can't see what I am doing wrong here. I have the class:
#include <sys/time.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_randist.h>
#include <cmath>
#include "randomnumbergenerator.h"
class RandomNumberGenerator
{
gsl_rng * rn;
public:
RandomNumberGenerator();
~RandomNumberGenerator();
double univariate();
void bivariateGaussian(double rho, double &x, double &y);
};
long currentMicroseconds()
{
struct timeval now;
gettimeofday(&now, NULL);
return now.tv_usec;
}
RandomNumberGenerator::RandomNumberGenerator()
{
const gsl_rng_type * T;
gsl_rng_env_setup();
//T = gsl_rng_default;
T = gsl_rng_mt19937;
rn = gsl_rng_alloc (T);
gsl_rng_set(rn,currentMicroseconds());
}
double RandomNumberGenerator::univariate()
{
return gsl_rng_uniform(rn);
}
void RandomNumberGenerator::bivariateGaussian(double rho, double &x, double &y)
{
gsl_ran_bivariate_gaussian (rn, 1.0, 1.0, rho, &x, &y);
}
RandomNumberGenerator::~RandomNumberGenerator()
{
gsl_rng_free (rn);
}
Which I call from here:
double x;
double y;
rng.bivariateGaussian(rho, x, y);
but I get a segmentation fault on gsl_ran_bivariate_gaussian (rn, 1.0, 1.0, rho, &x, &y);
Any idea?