projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Change type of variables whose addresses are passed to dict_get_vars()
[pspp]
/
src
/
sample.c
diff --git
a/src/sample.c
b/src/sample.c
index ce4d7758b15fc6701da5645f9c14733cc6c0a45a..57548c1cd306fc95e0c3bdc06ba915deeed1bdb8 100644
(file)
--- a/
src/sample.c
+++ b/
src/sample.c
@@
-14,20
+14,25
@@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
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., 5
9 Temple Place - Suite 330
, Boston, MA
- 0211
1-1307
, USA. */
+ Foundation, Inc., 5
1 Franklin Street, Fifth Floor
, Boston, MA
+ 0211
0-1301
, USA. */
#include <config.h>
#include <config.h>
+#include <gsl/gsl_rng.h>
+#include <limits.h>
#include <stdio.h>
#include <math.h>
#include "alloc.h"
#include "command.h"
#include "error.h"
#include "lexer.h"
#include <stdio.h>
#include <math.h>
#include "alloc.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"
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
#include "debug-print.h"
/* The two different types of samples. */
#include "debug-print.h"
/* The two different types of samples. */
@@
-43,11
+48,11
@@
struct sample_trns
struct trns_header h;
int type; /* One of TYPE_*. */
int n, N; /* TYPE_A_FROM_B: n from N. */
struct trns_header h;
int type; /* One of TYPE_*. */
int n, N; /* TYPE_A_FROM_B: n from N. */
- int m, t; /* TYPE_A_FROM_B: #
select
ed so far; # so far. */
-
int frac; /* TYPE_FRACTION: a fraction out of 65536
. */
+ int m, t; /* TYPE_A_FROM_B: #
pick
ed so far; # so far. */
+
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)
@@
-56,14
+61,15
@@
cmd_sample (void)
int type;
int a, b;
int type;
int a, b;
- int frac;
-
- lex_match_id ("SAMPLE");
+ unsigned frac;
if (!lex_force_num ())
return CMD_FAILURE;
if (!lex_force_num ())
return CMD_FAILURE;
- if (!lex_i
nteger_p
())
+ if (!lex_i
s_integer
())
{
{
+ 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)
{
@@
-72,7
+78,7
@@
cmd_sample (void)
return CMD_FAILURE;
}
return CMD_FAILURE;
}
- frac = tokval *
65536
;
+ frac = tokval *
(max - min) + min
;
a = b = 0;
}
else
a = b = 0;
}
else
@@
-97,13
+103,6
@@
cmd_sample (void)
}
lex_get ();
}
lex_get ();
-#if DEBUGGING
- if (type == TYPE_FRACTION)
- printf ("SAMPLE %g.\n", frac / 65536.);
- 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;
@@
-117,19
+116,26
@@
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;
{
struct sample_trns *t = (struct sample_trns *) trns;
double U;
- if (t->type == TYPE_FRACTION)
- return (rand_simple (0x10000) <= t->frac) - 2;
+ if (t->type == TYPE_FRACTION)
+ {
+ if (gsl_rng_get (get_rng ()) <= t->frac)
+ return -1;
+ else
+ return -2;
+ }
if (t->m >= t->n)
return -2;
if (t->m >= t->n)
return -2;
- U =
rand_uniform (1
);
+ 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++;