Adopt use of gnulib for portability.
[pspp-builds.git] / src / sample.c
index 8db7c8372a0bac9695a8d7641de351256460b805..57548c1cd306fc95e0c3bdc06ba915deeed1bdb8 100644 (file)
 
    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 <config.h>
+#include <gsl/gsl_rng.h>
 #include <limits.h>
 #include <stdio.h>
 #include <math.h>
 #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. */
@@ -61,8 +65,11 @@ cmd_sample (void)
 
   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)
        {
@@ -71,7 +78,7 @@ cmd_sample (void)
          return CMD_FAILURE;
        }
          
-      frac = tokval * UINT_MAX;
+      frac = tokval * (max - min) + min;
       a = b = 0;
     }
   else
@@ -119,7 +126,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;
@@ -128,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++;