From: Mark Wooding Date: Thu, 28 Apr 2022 17:27:19 +0000 (+0100) Subject: math/pgen.c (pgen_test): Use random witnesses only. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/commitdiff_plain/a938be516ed8fd8313ff3d061dd4b0f2d9acfa0e?hp=d2679863cf27b0812a4b88397be1ebf0b1319305 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. --- 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); }