private bool CheckProbablePrime(
int certainty,
Random random)
{
Debug.Assert(certainty > 0);
Debug.Assert(CompareTo(Two) > 0);
Debug.Assert(TestBit(0));
// Try to reduce the penalty for really small numbers
int numLists = System.Math.Min(BitLength - 1, primeLists.Length);
for (int i = 0; i < numLists; ++i)
{
int test = Remainder(primeProducts[i]);
int[] primeList = primeLists[i];
for (int j = 0; j < primeList.Length; ++j)
{
int prime = primeList[j];
int qRem = test % prime;
if (qRem == 0)
{
// We may find small numbers in the list
return BitLength < 16 && IntValue == prime;
}
}
}
// TODO Special case for < 10^16 (RabinMiller fixed list)
// if (BitLength < 30)
// {
// RabinMiller against 2, 3, 5, 7, 11, 13, 23 is sufficient
// }
// TODO Is it worth trying to create a hybrid of these two?
return RabinMillerTest(certainty, random);
// return SolovayStrassenTest(certainty, random);
// bool rbTest = RabinMillerTest(certainty, random);
// bool ssTest = SolovayStrassenTest(certainty, random);
//
// Debug.Assert(rbTest == ssTest);
//
// return rbTest;
}