+Sat Dec 10 23:30:19 2005 Ben Pfaff <blp@gnu.org>
+
+ Separate random numbers from other settings because of GSL
+ dependency.
+
+ * Makefile.am: Add random.c, random.h to sources.
+
+ * glob.c: (init_glob) Call random_init().
+ (done_glob) Call random_done().
+
+ * settings.c: (static var rng) Move to random.c.
+ (done_settings) Move freeing of RNG to random_done().
+ (get_rng) Move to random.c
+ (set_rng) Ditto.
+
+ * random.c: New file.
+
+ * random.h: New file.
+
Sat Dec 10 18:13:36 2005 Ben Pfaff <blp@gnu.org>
Separate settings and the SET command, for modularity.
pool.h \
postscript.c \
print.c \
+ random.c \
+ random.h \
range-prs.c \
range-prs.h \
recode.c \
#include "gsl-extras/gsl-extras.h"
#include "misc.h"
#include "moments.h"
+#include "random.h"
#include "settings.h"
#include "str.h"
#include "val.h"
#include "lexer.h"
#include "magic.h"
#include "main.h"
+#include "random.h"
#include "settings.h"
#include "str.h"
#include "var.h"
}
- init_settings();
+ init_settings ();
+ random_init ();
/* log.h */
logging = 1;
cancel_transformations ();
dict_destroy (default_dict);
free (logfn);
+ random_done ();
done_settings ();
ds_destroy (&tokstr);
--- /dev/null
+/* PSPP - computes sample statistics.
+ Copyright (C) 1997-9, 2000, 2005 Free Software Foundation, Inc.
+ Written by Ben Pfaff <blp@gnu.org>.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+#include <config.h>
+#include "random.h"
+#include <time.h>
+#include "xalloc.h"
+
+static gsl_rng *rng;
+
+void
+random_init (void)
+{
+}
+
+void
+random_done (void)
+{
+ if (rng != NULL)
+ gsl_rng_free (rng);
+}
+
+/* Returns the current random number generator. */
+gsl_rng *
+get_rng (void)
+{
+ if (rng == NULL)
+ set_rng (time (0));
+ return rng;
+}
+
+/* Initializes or reinitializes the random number generator with
+ the given SEED. */
+void
+set_rng (unsigned long seed)
+{
+ rng = gsl_rng_alloc (gsl_rng_mt19937);
+ if (rng == NULL)
+ xalloc_die ();
+ gsl_rng_set (rng, seed);
+}
--- /dev/null
+/* PSPP - computes sample statistics.
+ Copyright (C) 1997-9, 2000, 2005 Free Software Foundation, Inc.
+ Written by Ben Pfaff <blp@gnu.org>.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA. */
+
+#ifndef RANDOM_H
+#define RANDOM_H 1
+
+#include <gsl/gsl_rng.h>
+
+void random_init (void);
+void random_done (void);
+
+gsl_rng *get_rng (void);
+void set_rng (unsigned long seed);
+
+#endif /* random.h */
#include "command.h"
#include "error.h"
#include "lexer.h"
-#include "settings.h"
+#include "random.h"
#include "str.h"
#include "var.h"
#include "magic.h"
#include "log.h"
#include "output.h"
+#include "random.h"
#include "var.h"
#include "format.h"
#include "copyleft.h"
#include <config.h>
#include "settings.h"
#include <assert.h>
+#include <stdlib.h>
#include <time.h>
#include "format.h"
#include "val.h"
CC_INITIALIZER,
};
-static gsl_rng *rng;
-
static bool testing_mode = false;
static int global_algorithm = ENHANCED;
void
done_settings (void)
{
- if (rng != NULL)
- gsl_rng_free (rng);
-
free (prompt);
free (cprompt);
free (dprompt);
/* Approximate maximum amount of memory to use for cases, in
bytes. */
size_t
-get_workspace(void)
+get_workspace (void)
{
return workspace;
}
cc[idx] = *cc_;
}
-/* Returns the current random number generator. */
-gsl_rng *
-get_rng (void)
-{
- if (rng == NULL)
- set_rng (time (0));
- return rng;
-}
-
-/* Initializes or reinitializes the random number generator with
- the given SEED. */
-void
-set_rng (unsigned long seed)
-{
- rng = gsl_rng_alloc (gsl_rng_mt19937);
- if (rng == NULL)
- xalloc_die ();
- gsl_rng_set (rng, seed);
-}
-
/* Are we in testing mode? (e.g. --testing-mode command line
option) */
bool
const struct custom_currency *get_cc (int idx);
void set_cc (int idx, const struct custom_currency *);
-#include <gsl/gsl_rng.h>
-
-gsl_rng *get_rng (void);
-void set_rng (unsigned long seed);
-
bool get_testing_mode (void);
void set_testing_mode (bool);