0

I'm trying to use the random number generator from the GSL. In my code I have something like

...
gsl_rng * r;  /* global generator for Random Numbers*/

void init_rand_generator( int seed ){
    /* Random numbers initialization */
    const gsl_rng_type * T;
    gsl_rng_env_setup();
    gsl_rng_default_seed = seed;
    T = gsl_rng_default;
    r = gsl_rng_alloc( T );    

}
...

The problem is that, when I call the init_rand_generator( seed ) function from another function, in order to use gsl_rng_uniform( r ), the memory blows up and my system hangs. However, when I initialize the random number variables in the function where I use the gsl_rng_uniform( r ) function, everything works fine. I don't know what's the problem.

PerroNoob
  • 843
  • 2
  • 16
  • 36
  • 1
    That sounds like you've got an unintended unterminated recursion. Check whether, eg, gsl_rng_env_setup() is calling init_rand_generator(). A debugger is a useful tool... or analyzing a coredump may give you similar information about what's calling what calling what. – keshlam Mar 13 '14 at 03:05
  • 1
    HOWEVER: What's setting gsl_rng_default before you assign it to T? A bad pointer there could ruin your whole day... – keshlam Mar 13 '14 at 03:06
  • Thanks for your answer. According to the documentation `This function reads the environment variables GSL_RNG_TYPE and GSL_RNG_SEED and uses their values to set the corresponding library variables gsl_rng_default and gsl_rng_default_seed` . Maybe, as you said, when I do `gsl_rng_default_seed = seed`, it is trying to read the seed from the same function :/ – PerroNoob Mar 13 '14 at 13:26
  • Actually, I found the problem. In a function I was calling other function which had also `init_rand_generator( seed )` and it produced an infinite recursion. Thanks for pointing that out, I could not figure that out before. – PerroNoob Mar 13 '14 at 13:35

0 Answers0