From a938be516ed8fd8313ff3d061dd4b0f2d9acfa0e Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Thu, 28 Apr 2022 18:27:19 +0100 Subject: [PATCH] math/pgen.c (pgen_test): Use random witnesses only. This means that we no longer need to distinguish the first round of a Rabin--Miller test loop, which in turn will allow a more useful change in the future. --- math/pgen.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/math/pgen.c b/math/pgen.c index f0606591..f10c163e 100644 --- a/math/pgen.c +++ b/math/pgen.c @@ -118,6 +118,7 @@ int pgen_jump(int rq, pgen_event *ev, void *p) int pgen_test(int rq, pgen_event *ev, void *p) { rabin *r = p; + mp *a = MP_NEW; int rc = PGEN_ABORT; switch (rq) { @@ -126,13 +127,8 @@ int pgen_test(int rq, pgen_event *ev, void *p) rc = PGEN_TRY; break; case PGEN_TRY: - if (!ev->tests) - rc = rabin_rtest(r, MP_TWO); - else { - mp *a = mprand_range(MP_NEW, ev->m, ev->r, 0); - rc = rabin_rtest(r, a); - mp_drop(a); - } + a = mprand_range(a, ev->m, ev->r, 0); + rc = rabin_rtest(r, a); break; case PGEN_DONE: rabin_destroy(r); @@ -140,6 +136,7 @@ int pgen_test(int rq, pgen_event *ev, void *p) break; } + mp_drop(a); return (rc); } -- 2.11.0