Remove "Written by Ben Pfaff <blp@gnu.org>" lines everywhere.
[pspp-builds.git] / src / math / random.c
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000, 2005 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17    02110-1301, USA. */
18
19 #include <config.h>
20 #include "random.h"
21 #include <time.h>
22 #include "xalloc.h"
23
24 static gsl_rng *rng;
25
26 void
27 random_init (void) 
28 {
29 }
30
31 void
32 random_done (void) 
33 {
34   if (rng != NULL) 
35     gsl_rng_free (rng);
36 }
37
38 /* Returns the current random number generator. */
39 gsl_rng *
40 get_rng (void)
41 {
42   if (rng == NULL)
43     set_rng (time (0));
44   return rng;
45 }
46
47 /* Initializes or reinitializes the random number generator with
48    the given SEED. */
49 void
50 set_rng (unsigned long seed) 
51 {
52   rng = gsl_rng_alloc (gsl_rng_mt19937);
53   if (rng == NULL)
54     xalloc_die ();
55   gsl_rng_set (rng, seed);
56 }