Don't use the @pgen@ random number generator for generating primes: it's
authormdw <mdw>
Sat, 3 Feb 2001 11:59:07 +0000 (11:59 +0000)
committermdw <mdw>
Sat, 3 Feb 2001 11:59:07 +0000 (11:59 +0000)
only for testing them.  Use a caller-supplied one instead.

limlee.c
limlee.h

index afc1e7d..3f8435b 100644 (file)
--- a/limlee.c
+++ b/limlee.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: limlee.c,v 1.7 2001/01/25 21:40:44 mdw Exp $
+ * $Id: limlee.c,v 1.8 2001/02/03 11:59:07 mdw Exp $
  *
  * Generate Lim-Lee primes
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: limlee.c,v $
+ * Revision 1.8  2001/02/03 11:59:07  mdw
+ * Don't use the @pgen@ random number generator for generating primes: it's
+ * only for testing them.  Use a caller-supplied one instead.
+ *
  * Revision 1.7  2001/01/25 21:40:44  mdw
  * Remove dead code now that the new stepper structure is trustworthy.
  *
@@ -156,8 +160,7 @@ again:
 
 static void llfree(limlee_factor *f, limlee_stepctx *l)
 {
-  if (f->p)
-    mp_drop(f->p);
+  mp_drop(f->p);
 }
 
 static const limlee_primeops primeops_simple = { llgen, llfree };
@@ -211,7 +214,6 @@ static int init(pgen_event *ev, limlee_stepctx *l)
   /* --- Other bits of initialization --- */
 
   l->seq = 0;
-  l->r = ev->r;
   dstr_create(&l->d);
   if (!l->pops) {
     l->pops = &primeops_simple;
@@ -246,9 +248,7 @@ static int next(int rq, pgen_event *ev, limlee_stepctx *l)
   mp *p;
   int rc;
 
-  if (ev->m)
-    mp_drop(ev->m);
-  l->r = ev->r;
+  mp_drop(ev->m);
 
   for (;;) {
     size_t i;
@@ -408,6 +408,7 @@ mp *limlee(const char *name, mp *d, mp *newp,
   l.pops = 0;
   l.iev = iev;
   l.iec = iec;
+  l.r = r;
 
   d = pgen(name, d, 0, oev, oec, on, limlee_step, &l,
           rabin_iters(pl), pgen_test, &rr);
index 2802585..0131cb0 100644 (file)
--- a/limlee.h
+++ b/limlee.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: limlee.h,v 1.3 2000/12/06 20:33:27 mdw Exp $
+ * $Id: limlee.h,v 1.4 2001/02/03 11:59:07 mdw Exp $
  *
  * Generate Lim-Lee primes
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: limlee.h,v $
+ * Revision 1.4  2001/02/03 11:59:07  mdw
+ * Don't use the @pgen@ random number generator for generating primes: it's
+ * only for testing them.  Use a caller-supplied one instead.
+ *
  * Revision 1.3  2000/12/06 20:33:27  mdw
  * Make flags be macros rather than enumerations, to ensure that they're
  * unsigned.
@@ -82,6 +86,7 @@ typedef struct limlee_stepctx {
   void *pc;                            /* Context ptr for generator ops */
   pgen_proc *iev;                      /* Event handler for inner @pgen@ */
   void *iec;                           /* Context for inner @pgen@ */
+  grand *r;                            /* Random number generator */
 
   /* --- Output values --- */
 
@@ -91,7 +96,6 @@ typedef struct limlee_stepctx {
   /* --- Maintained internally --- */
 
   octet *c;                            /* Combination byte-flag vector */
-  grand *r;                            /* Random number generator */
   unsigned long seq;                   /* Sequence number for primes */
   size_t poolsz;                       /* Size of the small-prime pool */
   dstr d;                              /* String for subprime name */