projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
removed src/version.c from pspp_SOURCES, as it is generated by autoconf,
[pspp]
/
src
/
sample.c
diff --git
a/src/sample.c
b/src/sample.c
index 8a5406d14299daacb7806a5022f0c9cfb34617a6..96c5f4d9070705fadd7cebb297753aaec9ebd91b 100644
(file)
--- a/
src/sample.c
+++ b/
src/sample.c
@@
-18,6
+18,7
@@
02111-1307, USA. */
#include <config.h>
02111-1307, USA. */
#include <config.h>
+#include <gsl/gsl_rng.h>
#include <limits.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <stdio.h>
#include <math.h>
@@
-25,7
+26,7
@@
#include "command.h"
#include "error.h"
#include "lexer.h"
#include "command.h"
#include "error.h"
#include "lexer.h"
-#include "
random
.h"
+#include "
settings
.h"
#include "str.h"
#include "var.h"
#include "str.h"
#include "var.h"
@@
-48,7
+49,7
@@
struct sample_trns
unsigned frac; /* TYPE_FRACTION: a fraction of UINT_MAX. */
};
unsigned frac; /* TYPE_FRACTION: a fraction of UINT_MAX. */
};
-
int sample_trns_proc (struct trns_header *, struct ccase *)
;
+
static trns_proc_func sample_trns_proc
;
int
cmd_sample (void)
int
cmd_sample (void)
@@
-59,12
+60,13
@@
cmd_sample (void)
int a, b;
unsigned frac;
int a, b;
unsigned frac;
- lex_match_id ("SAMPLE");
-
if (!lex_force_num ())
return CMD_FAILURE;
if (!lex_integer_p ())
{
if (!lex_force_num ())
return CMD_FAILURE;
if (!lex_integer_p ())
{
+ unsigned long min = gsl_rng_min (get_rng ());
+ unsigned long max = gsl_rng_max (get_rng ());
+
type = TYPE_FRACTION;
if (tokval <= 0 || tokval >= 1)
{
type = TYPE_FRACTION;
if (tokval <= 0 || tokval >= 1)
{
@@
-73,7
+75,7
@@
cmd_sample (void)
return CMD_FAILURE;
}
return CMD_FAILURE;
}
- frac = tokval *
UINT_MAX
;
+ frac = tokval *
(max - min) + min
;
a = b = 0;
}
else
a = b = 0;
}
else
@@
-98,13
+100,6
@@
cmd_sample (void)
}
lex_get ();
}
lex_get ();
-#if DEBUGGING
- if (type == TYPE_FRACTION)
- printf ("SAMPLE %g.\n", frac / (double) UINT_MAX);
- else
- printf ("SAMPLE %d FROM %d.\n", a, b);
-#endif
-
trns = xmalloc (sizeof *trns);
trns->h.proc = sample_trns_proc;
trns->h.free = NULL;
trns = xmalloc (sizeof *trns);
trns->h.proc = sample_trns_proc;
trns->h.free = NULL;
@@
-118,15
+113,17
@@
cmd_sample (void)
return lex_end_of_command ();
}
return lex_end_of_command ();
}
-int
-sample_trns_proc (struct trns_header * trns, struct ccase *c UNUSED)
+/* Executes a SAMPLE transformation. */
+static int
+sample_trns_proc (struct trns_header * trns, struct ccase *c UNUSED,
+ int case_num UNUSED)
{
struct sample_trns *t = (struct sample_trns *) trns;
double U;
if (t->type == TYPE_FRACTION)
{
{
struct sample_trns *t = (struct sample_trns *) trns;
double U;
if (t->type == TYPE_FRACTION)
{
- if (
rng_get_unsigned (pspp
_rng ()) <= t->frac)
+ if (
gsl_rng_get (get
_rng ()) <= t->frac)
return -1;
else
return -2;
return -1;
else
return -2;
@@
-135,7
+132,7
@@
sample_trns_proc (struct trns_header * trns, struct ccase *c UNUSED)
if (t->m >= t->n)
return -2;
if (t->m >= t->n)
return -2;
- U =
rng_get_double (pspp
_rng ());
+ U =
gsl_rng_uniform (get
_rng ());
if ((t->N - t->t) * U >= t->n - t->m)
{
t->t++;
if ((t->N - t->t) * U >= t->n - t->m)
{
t->t++;