I just learned about JUCE today, so I’m having fun just exploring!
I noticed in the Miller-Rabin test for testing for pseudo-primes that the base chosen in each iteration is random. But it’s actually best for the base to be a prime, since the test is based on Fermat’s little theorem, which is applicable only for primes. Any prime works, but small primes are more efficient to use in the computation, so usually you just test in order (2, 3, 5, 7, 11, 13, 17, 19…)
Actually in practice, using random numbers as base tests won’t misidentify a prime as nonprime, though, but it does increase the probability of nonprimes to pass make the test less efficient. Using prime bases only has no drawbacks. So JUCE’s current method will still work, but it will be both slower and less likely to spot composites than a prime basis set of tests.
This page has a lot more info on using MR, especially some useful guarantees of primality for different ranges of N.
The JUCE test could also be tuned more with some initial GCD computations to eliminate most composites before firing up the (slow) pseudo-prime computation, but a GCD step really is optional and probably the speed of prime testing isn’t a priority for JUCE. Still, it’s easy to add something to Prime::isProbabablyPrime like:
[code]const BitArray screen (23571113171923);
BitArray GCD(findGreatestCommonDivisor(number, screen));
if (GCD != one) return false; // not prime, “number” has a small divisor.
Forgive me if I misunderstand the JUCE code! I am just looking over it for the first time and I was instantly impressed by the clean and clear style.