3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 James Theiler, Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include <gsl/gsl_rng.h>
25 #include <gsl/gsl_errno.h>
27 /* The initial defaults are defined in the file mt.c, so we can get
28 access to the static parts of the default generator. */
31 gsl_rng_env_setup (void)
33 unsigned long int seed = 0;
34 const char *p = getenv ("GSL_RNG_TYPE");
38 const gsl_rng_type **t, **t0 = gsl_rng_types_setup ();
42 /* check GSL_RNG_TYPE against the names of all the generators */
44 for (t = t0; *t != 0; t++)
46 if (strcmp (p, (*t)->name) == 0)
53 if (gsl_rng_default == 0)
57 fprintf (stderr, "GSL_RNG_TYPE=%s not recognized\n", p);
58 fprintf (stderr, "Valid generator types are:\n");
60 for (t = t0; *t != 0; t++)
62 fprintf (stderr, " %18s", (*t)->name);
72 GSL_ERROR_VAL ("unknown generator", GSL_EINVAL, 0);
75 fprintf (stderr, "GSL_RNG_TYPE=%s\n", gsl_rng_default->name);
79 gsl_rng_default = gsl_rng_mt19937;
82 p = getenv ("GSL_RNG_SEED");
86 seed = strtoul (p, 0, 0);
87 fprintf (stderr, "GSL_RNG_SEED=%lu\n", seed);
90 gsl_rng_default_seed = seed;
92 return gsl_rng_default;