#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <cmath>

double normrnd(double mu,double sigma)
{
       double chi,eta,ret;
       chi=drand48();
       eta=drand48();
       ret=mu+sigma*sqrt(-2*log(chi))*cos(2*M_PI*eta);
       return ret;
}

main()
{
      int i, nmbrofsim;
      double tid,est,mu,sigma;
      clock_t ticks1, ticks2;
      unsigned short myseed;

      myseed=7509;
      srand48(myseed);

      mu=0.0;
      sigma=1.0;
      est=0.0;

      ticks1=clock()/CLOCKS_PER_SEC;

      nmbrofsim=10000000;
      for(i = 0; i < nmbrofsim; i = i + 1)
      {
            est = est + normrnd(mu,sigma);
      }

      est = est/nmbrofsim;

      ticks2=clock()/CLOCKS_PER_SEC;
      tid=difftime(ticks2, ticks1);

      printf("Time is %f\n", tid);
      printf("Est is %f\n", est);
      return 0;
}
  