help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] Random number generator: compiling issue on a Mac (10.4.11)


From: Marco Tului
Subject: [Help-gsl] Random number generator: compiling issue on a Mac (10.4.11)
Date: Sat, 11 Apr 2009 15:52:17 +0200

Hi all,
excuse me, I've compiled and installed the GSL on my Mac, running Mac Os
10.4.11 (Tiger). Now I'm trying to compile a random number generator class,
for a library of mine. Here the code:

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#ifndef RANDOM_GENERATOR__HPP
#define RANDOM_GENERATOR__HPP


#include <gsl/gsl_rng.h> // here we use the "GNU Scientific Library" (GSL)
to obtain a random number
#include <gsl/gsl_randist.h> // to obtain gsl_ran_gaussian_pdf()
#include <iostream>
using namespace std;


enum Distribution_type {
  NORMAL = 1,
  UNIFORM = 2,
  BINARY = 3
};


class Random_generator {

  private:
    const gsl_rng_type *_type_gen;
    gsl_rng *_gen; // 'gen' is the (random) generator

    Distribution_type _distr_type;


  public:
    // default CONSTRUCTOR
    Random_generator( ) {
      _type_gen = gsl_rng_default;
      _gen = gsl_rng_alloc(_type_gen); // in this way we allocate, in the
standard way, the generator 'gen'
    };

    // DESTRUCTOR
    ~Random_generator( ) {
      gsl_rng_free(_gen); // we free the memory associated with the
generator 'r'
    };


    double Get_rnd_generator( ) { // by default we assume Distribution_type
= NORMAL
      return gsl_ran_gaussian(_gen, 1) ;
    };



    double Get_rnd_generator(Distribution_type distr_type_init) {
      if(distr_type_init == NORMAL) {
        return gsl_ran_gaussian(_gen, 1);
      }
      else if(distr_type_init == UNIFORM) {
        // return sample da distribuzione uniforme...
      }
      else if(distr_type_init == BINARY) {
        // return sample da distribuzione binaria
      }
    };



    // vv implementare delle funzioni di interfaccia, ad esempio per far in
modo ci sia controllo sul corretto valore
    // di sigma (che non sia negativo) etc.


 /*
    // CONSTRUCTOR for obtaining a random number from a Gaussian
distribution,
    // centered in the desired value and with the requested sigma
    Random(double mu, double sigma) {
      double x, z;
      type_gen = gsl_rng_default;
      gen = gsl_rng_alloc(type_gen); // in this way we allocate, in the
standard way, the generator 'r'

      x = gsl_ran_gaussian(gen, sigma);
      z = mu + x;
      Set_random(z);
    };
*/


};


#endif
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


By terminal, I write "g++ -c random_generator.cpp -lgsl -lgslcblas -lm" but
I obtain in response the following errors:

i686-apple-darwin8-g++-4.0.1: -lgsl: linker input file unused because
linking not done
i686-apple-darwin8-g++-4.0.1: -lgslcblas: linker input file unused because
linking not done
i686-apple-darwin8-g++-4.0.1: -lm: linker input file unused because linking
not done

I don't understand this: could anyone help me? Please, it's important, and
quite urgent.



Thanks in advance,

Marco Tului.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]