Hi guys,

I'm trying to use the random number generator as part of the GSL library and it is working fine for a few hundred 'rounds' of my code (it is used quite a few times per round) but then i get an error message in the command window:

```
gsl: rng.c:46: ERROR: failed to allocate space for rng state
Default GSL error handler invoked.
```

A quick look at the rng.c shows that this is an error from the gsl_rng_alloc part (see bottom)and this is what I can find about that function on that topic:

```
— Function: gsl_rng * gsl_rng_alloc (const gsl_rng_type * T)
This function returns a pointer to a newly-created instance of a random number generator of type T. For example, the following code creates an instance of the Tausworthe generator,
gsl_rng * r = gsl_rng_alloc (gsl_rng_taus);
If there is insufficient memory to create the generator then the function returns a null pointer and the error handler is invoked with an error code of GSL_ENOMEM.
```

But unfortunately I don't quite understand what it all means - I'm quite new to all this, as is probably clear...

Could you please help explain what is happening here and possible way of stopping this happening?

I've tried changing the size and way of declaring the seed, putting the definition just once at the start of the code and then at the start of each loop where it is used and it seems to make no difference.

Any help very much appreciated.

If there's anything else I've left out that you would need to know, please just ask.

Thanks!

______________________________________________

```
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_rng.h>
gsl_rng *
gsl_rng_alloc (const gsl_rng_type * T)
{
gsl_rng *r = (gsl_rng *) malloc (sizeof (gsl_rng));
if (r == 0)
{
GSL_ERROR_VAL ("failed to allocate space for rng struct",
GSL_ENOMEM, 0);
};
r->state = malloc (T->size);
if (r->state == 0)
{
free (r); /* exception in constructor, avoid memory leak */
GSL_ERROR_VAL ("failed to allocate space for rng state",
GSL_ENOMEM, 0);
};
r->type = T;
gsl_rng_set (r, gsl_rng_default_seed); /* seed the generator */
return r;
}
```