/*@@@@@@@@@@@@@@@@@@@@@@@@@@@ GSL_RandomGen.h @@@@@@@@@@@@@@@@@@@@@@@@@
 Random Option Pricing
 Summer 2002
 Authors: A. Korobchevsky
          S. Ferrando
 Ryerson University ALL RIGHTS RESERVED
 
 Purpose: Declares wrapper class to GSL Random generator
 Instance variables: name_ - generator algoritm selection (mt, taus, gfsr)
							seed_ - seed to start the generation from
                     gsl_rng - pointer to defined in GSL random generator struct  
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/




#ifndef GSL_RANDG_H_
#define GSL_RANDG_H_

#include <cstdio>
#include <string>
using namespace std;

#include "../../Lib/MyGSL/Headers/myconfig.h"
#include "../../Lib/MyGSL/Headers/mygsl_rng.h"
#include "../../Lib/MyGSL/Headers/mygsl_errno.h"





// BEGIN All
class GSL_RandomGen
{ public:

    /************************** GSL_RandomGen ***************************
     * Function: Constructor
     * Purpose: Creates new generator object
     * Param: generator name, seed to start, precision in number of digits after the decimal point
     * Returns: N/A
     ********************************************************************/
     GSL_RandomGen(string = "mt19937", long = 1, int = 4);




    /************************* ~GSL_RandomGen ***************************
     * Function: Destructor
     * Purpose: Dellocates memory by using routine defined in GSL
     * Param: N/A
     * Returns: N/A
     ********************************************************************/
    ~GSL_RandomGen() { gsl_rng_free(r_); }




    /*************************** getName ********************************
     * Function: getName
     * Purpose: Accessor to generator name parameter
     * Param: N/A
     * Returns: generator name
     ********************************************************************/
    string getName() { return gsl_rng_name(r_); }




    /*************************** setSeed ********************************
     * Function: setSeed
     * Purpose: Sets generator seed to specified value 
     * Param: seed
     * Returns: N/A
     ********************************************************************/ 
    void setSeed(long);




    /****************************** next ********************************
     * Function: next
     * Purpose: Returns uniform [0..1] random value
     * Param: N/A
     * Returns: Uniform random value
     ********************************************************************/ 
    double next() { return gsl_rng_uniform(r_); }




    /*************************** nextInt ********************************
     * Function: nextInt
     * Purpose: Returns random integer in [0..range] 
     * Param: upper range boundary
     * Returns: Random integer
     ********************************************************************/ 
    int nextInt(int range) { return gsl_rng_uniform_int(r_, range); }




    /*************************** gauss **********************************
     * Function: gauss
     * Purpose: Returns random normal with mean 0 and given standard deviation 
     * Param: standard deviation
     * Returns: Random double
     ********************************************************************/ 
    double gauss(double);
  



    /************************* print **********************************
     * Function: print
     * Purpose: Display contents of the Binom Random generator object
     * Param: fp - output file stream
     * Returns: N/A
     ********************************************************************/
    void print(FILE* fp) { fprintf(fp, "Gen: %s, seed: %d\n", name_.c_str(), seed_);  }

  private:
    string name_;
    long seed_;
    gsl_rng* r_;
};

// END All
#endif
