From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Teuben To: Brian Gough Cc: gsl-discuss@sourceware.cygnus.com Subject: Re: fprintf(stderr,...) output in GSL routines (gsl_rng_env_setup) Date: Wed, 19 Dec 2001 13:20:00 -0000 Message-id: References: <15259.15112.921941.197191@debian> X-SW-Source: 2001/msg00485.html > The environment variables are completely optional -- they are only > used if you explicitly call gsl_rng_env_setup(). You can set the > parameters by direct assignment in C. e.g. > > #include > > int main () { > .... > gsl_rng_default_seed = 123; > gsl_rng_default_type = gsl_rng_ran3 ; > yes, I understood that also from the example, but i actually like the idea of the user giving control of the random number generator. So in the code the user can supply seed=0,ran3 where they are both optional. The method of assigning to gsl_rng_default_type would require me to manually build a large list of (to me officially unknown) names, whereas the putenv() method has the nice side-effect that if you say seed=0,help you get ... Valid generator types are: cmrg gfsr4 minstd mrg mt19937 r250 ran0 ran1 ran2 ran3 rand48 rand random128-bsd random128-glibc2 random128-libc5 random256-bsd random256-glibc2 random256-libc5 random32-bsd random32-glibc2 random32-libc5 random64-bsd random64-glibc2 random64-libc5 random8-bsd random8-glibc2 random8-libc5 random-bsd random-glibc2 random-libc5 randu ranf ranlux389 ranlux ranlxd1 ranlxd2 ranlxs0 ranlxs1 ranlxs2 ranmar slatec taus transputer tt800 uni32 uni vax zuf so, I got the following code from that idea: is = burststring(init,", "); /* parse init as "[seed[,name]]" */ nis = xstrlen(is,sizeof(string))-1; if (nis > 0) { /* seed is first, but optional */ iseed = natoi(is[0]); if (iseed > 0 || streq(is[0],"+0")) { sprintf(my_gsl_seed,"%s=%s",env_seed,is[0]); } else { iseed = set_xrandom(iseed); sprintf(my_gsl_seed,"%s=%u",env_seed,iseed); } putenv(my_gsl_seed); if (nis > 1) { /* name is second, also optional */ sprintf(my_gsl_type,"%s=%s",env_type,is[1]); putenv(my_gsl_type); } } gsl_rng_env_setup(); /* initialize the rng (name/seed) setup */ my_T = gsl_rng_default; my_r = gsl_rng_alloc(my_T); dprintf(1,"GSL generator type: %s\n",gsl_rng_name(my_r)); dprintf(1,"GSL seed = %u\n",gsl_rng_default_seed); dprintf(1,"GSL first value = %u\n",gsl_rng_get(my_r)); You can see a call to set_xrandom(), that replaces a seed of 0,-1,-2 by seconds since 1970, clock-cycles or PID as seed. We found that to be useful for simulations. In linux there is also /dev/random, but I haven't been able to use that. peter