I am trying to implement the GSL uniform random number generator into my C++ program. Below is my entire program and I am having difficulties getting it to run properly. Any help would be greatly appreciated. Thanks for your time!
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <gsl\gsl_rng.h>
int main()
{
double CeOld;
double CgOld;
double r;
double Pe;
double Omega = .5;
double gamma = 1;
double Ce = 1/sqrt(2);
double Cg = 1/sqrt(2);
double T = 0.0;
double dT = 0.05;
double CeDot;
double CgDot;
double Sum;
ofstream position;
ofstream momentum;
positiondata.open("position.txt");
momentumdata.open("momentum.txt");
const gsl_rng_type * T;
gsl_rng * q;
gsl_rng_env_setup();
T = gsl_rng_default;
q = gsl_rng_alloc (T);
printf("Cg=%lf\n",Cg);
for(int i = 1; i < 10000; i++)
{
T=T+dT;
CgOld=Cg;
CeOld=Ce;
CeDot = (Omega/2)*Cg-(gamma/2)*Ce;
CgDot = -((Omega/2)*Ce);
r = gsl_rng_uniform(q);
if (r < (abs(Ce)*abs(Ce)*dT))
{
Cg = CeOld;
Ce = 0;
}
else{
Cg = CgOld+CgDot*dT;
Ce = CeOld+CeDot*dT;
}
Pe=abs(Ce)*abs(Ce);
printf("Pe=%lf\n",Pe);
Sum=sqrt(pow(Ce, 2.0)+ pow (Cg, 2.0));
Ce=Ce/Sum;
Cg=Cg/Sum;
};
return 0;
}