Jump to content

Miller–Rabin primality test: Difference between revisions

Line 4,487:
</lang>
 
=== This is a correct M-R test implementation for using bases > input. ===
This==== versionIt monkey patches '''class Integer''' to make it simpler to use. ====
==== It is deterministic for all integers < 3_317_044_064_679_887_385_961_981.====
==== Increase 'primes' array members for more "confidence" past this value. ====
 
<lang ruby>
Line 4,514 ⟶ 4,515:
d >>= 4 while (d & 0xf) == 0 # suck out factors of 2
(d >>= (d & 3)^2; d >>= (d & 1)^1) if d.even? # 4 bits at a time
witnesses.each do |b| # loopdo overM-R test with each witness basesbase
next if (b % self) == 0 # **skip base if a multiple of input**
s = d
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.