[Top][All Lists]

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

Re: [Help-gsl] about the function " gsl_ran_gaussian ( ) "

From: John D Lamb
Subject: Re: [Help-gsl] about the function " gsl_ran_gaussian ( ) "
Date: Mon, 11 Apr 2011 08:07:34 +0100

On Fri, 2011-04-08 at 19:49 -0400, Yi Cao wrote:
> Hello everyone,
>       I am now trying to generate some gauss random numbers (about size of
> 30,000).
>       I found the following function in GSL, but I am not clear how to use
> this function.
> 0. can I just call this function in my C++ code?

No. You need a random number generator first. You can create one using
gsl_rng_alloc but you have to free it with gsl_rng_free. If you want a C
++ that will do this then the following should work and you don’t have
to remember to free the random number generator.


class RNG {
  RNG() : rng( gsl_rng_alloc( gsl_rng_mt19937 ) ){};
  ~RNG(){ gsl_rng_free( rng ); }
  gsl_rng* get(){ return rng; }
  gsl_rng* rng;

RNG rng;


random_variate = mean + gsl_ran_gaussian( rng.get(),
standard_deviation );

> 1. If I use cygwin to compile the C++ code containing the function, can I
> just #include"gsl/gsl_randist.h" and then compile it?

You’ll have to link with gsl, gslcblas (or some other cblas) at some.
point. Otherwise, yes.

> 2. If I use linux (SUSE), do I have to install the GSL first and then
> compile the C++ code
> ?

Yes. You can’t use GSL without first installing it. On SuSE, link with g
++ … -lgsl -lgslcblas -lm

> 3.what is the first argument of the function----const gsl_rng *r ? what
> value should I assign to it?

That’s the gsl_rng* which you allocate and free with gsl_rng_alloc and
gsl_rng_free as in the C++ class above.


reply via email to

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