这可能是一个愚蠢的问题,但我看不出我在这里做错了什么。我有课:
#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);
}
我从这里调用:
double x;
double y;
rng.bivariateGaussian(rho, x, y);
但我得到一个分段错误gsl_ran_bivariate_gaussian (rn, 1.0, 1.0, rho, &x, &y);
任何的想法?