X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fsample.c;h=11e4ad66e64dd4c536478ba33dc119669ef053fc;hb=3bd4593ef9a57f23062c61ec465389f749ba3089;hp=ce5d18d8131de8a12e0fc5de27f5508356ec0e59;hpb=bc963dae9be291ea0a7cccf189d13e00d3797cfd;p=pspp-builds.git diff --git a/src/sample.c b/src/sample.c index ce5d18d8..11e4ad66 100644 --- a/src/sample.c +++ b/src/sample.c @@ -18,6 +18,7 @@ 02111-1307, USA. */ #include +#include #include #include #include @@ -25,7 +26,7 @@ #include "command.h" #include "error.h" #include "lexer.h" -#include "random.h" +#include "settings.h" #include "str.h" #include "var.h" @@ -59,12 +60,13 @@ cmd_sample (void) int a, b; unsigned frac; - lex_match_id ("SAMPLE"); - if (!lex_force_num ()) return CMD_FAILURE; - if (!lex_integer_p ()) + if (!lex_is_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) { @@ -73,7 +75,7 @@ cmd_sample (void) return CMD_FAILURE; } - frac = tokval * UINT_MAX; + frac = tokval * (max - min) + min; a = b = 0; } else @@ -98,13 +100,6 @@ cmd_sample (void) } 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; @@ -118,6 +113,7 @@ cmd_sample (void) return lex_end_of_command (); } +/* Executes a SAMPLE transformation. */ static int sample_trns_proc (struct trns_header * trns, struct ccase *c UNUSED, int case_num UNUSED) @@ -127,7 +123,7 @@ sample_trns_proc (struct trns_header * trns, struct ccase *c UNUSED, 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; @@ -136,7 +132,7 @@ sample_trns_proc (struct trns_header * trns, struct ccase *c UNUSED, 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++;