Subject: Re: Seed for RNG - msg#00038
List: lib.gsl.general
You can just set up your program to check if the environment variable
GSL_RNG_SEED has been set, and if not, change the value of
gsl_rng_default_seed based on the output of the time() function.
ex (put this after the call to gsl_rng_env_setup()):
if (!getenv("GSL_RNG_SEED")) gsl_rng_default_seed = time(0);
You'll also need to #include <stdlib.h>, if you haven't already, for
the getenv() function.
Alternatively, you can just call gsl_rng_set(r, time(0)) after you
allocate your generator. Checking the environment variable's probably
the better route, though -- it will allow your user to override using
time() to seed the generator.
You can also do the same trick to change the default generator you're
using.
ex:
if (!getenv("GSL_RNG_TYPE")) gsl_rng_default = gsl_rng_taus;
-Daniel
Johan van der Walt wrote:
I got my little code going for generating random numbers using the GSL
routines. Works fine. I now want to use a different seed every time I
run the code. But I don't want to enter a new seed on the command line
like this
$ GSL_RNG_TYPE="taus" GSL_RNG_SEED=123 ./a.out
every time I run the code.
How can I set the seed in the code?
Johan
_______________________________________________
Help-gsl mailing list
Help-gsl@xxxxxxx
http://lists.gnu.org/mailman/listinfo/help-gsl
Was this page helpful?
Thread at a glance:
Previous Message by Date:
click to view message preview
Re: Seed for RNG
On 28 feb 2008, at 19.40, Johan van der Walt wrote:
I got my little code going for generating random numbers using the
GSL routines. Works fine. I now want to use a different seed every
time I run the code. But I don't want to enter a new seed on the
command line like this
$ GSL_RNG_TYPE="taus" GSL_RNG_SEED=123 ./a.out
every time I run the code.
How can I set the seed in the code?
Johan
Use the computer clock to generate the seed.
-------------------------------------
This sig is dedicated to the advancement of Nuclear Power
Tommy Nordgren
tommy.nordgren@xxxxxxxxx
Previous Message by Thread:
click to view message preview
Re: Seed for RNG
Yeah,
Like this,
gsl_rng_set(rng, time(NULL));
you will also need to include the header file for time(), it think it
is,
#include <sys/types.h>
and
#include <time.h>
Cheers,
Dan.
On 28 Feb 2008, at 18:57, Tommy Nordgren wrote:
On 28 feb 2008, at 19.40, Johan van der Walt wrote:
I got my little code going for generating random numbers using the
GSL routines. Works fine. I now want to use a different seed every
time I run the code. But I don't want to enter a new seed on the
command line like this
$ GSL_RNG_TYPE="taus" GSL_RNG_SEED=123 ./a.out
every time I run the code.
How can I set the seed in the code?
Johan
Use the computer clock to generate the seed.
-------------------------------------
This sig is dedicated to the advancement of Nuclear Power
Tommy Nordgren
tommy.nordgren@xxxxxxxxx
_______________________________________________
Help-gsl mailing list
Help-gsl@xxxxxxx
http://lists.gnu.org/mailman/listinfo/help-gsl