X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fsample.c;h=57548c1cd306fc95e0c3bdc06ba915deeed1bdb8;hb=45b8514ebb8a7b10eb5d911a231a9fc7974f8ba9;hp=b721f2db9c1228464ed2b2c30486a63cfbf8cc08;hpb=2bfc3a138f308ffb38634a92b23bdc7b62592324;p=pspp-builds.git diff --git a/src/sample.c b/src/sample.c index b721f2db..57548c1c 100644 --- a/src/sample.c +++ b/src/sample.c @@ -14,10 +14,11 @@ 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., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ #include +#include #include #include #include @@ -25,10 +26,13 @@ #include "command.h" #include "error.h" #include "lexer.h" -#include "random.h" +#include "settings.h" #include "str.h" #include "var.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) + #include "debug-print.h" /* The two different types of samples. */ @@ -48,7 +52,7 @@ struct sample_trns 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) @@ -59,12 +63,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 +78,7 @@ cmd_sample (void) return CMD_FAILURE; } - frac = tokval * UINT_MAX; + frac = tokval * (max - min) + min; a = b = 0; } else @@ -98,13 +103,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,15 +116,17 @@ cmd_sample (void) 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) { - if (rng_get_unsigned (pspp_rng ()) <= t->frac) + if (gsl_rng_get (get_rng ()) <= t->frac) return -1; else return -2; @@ -135,7 +135,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++;