/// <summary> /// Determines whether BigInteger is prime number with probability that can be greater than requested probability /// </summary> /// <param name="number">The BigInteger to check</param> /// <param name="probability">Probability of error</param> /// <returns></returns> public bool IsPrime(BigInteger number, BigNumDec probability) { if (probability.Equals(0) || probability.Equals(1)) throw new ArgumentException("Probability must be in range (0; 1)"); int iterations = 1; BigNum baseNum = 0.25; while (true) { if (baseNum <= probability) break; baseNum *= 0.25; iterations++; } while (iterations > 0) { if (!IsPrime(number)) return false; --iterations; } return true; }
private int GetInterationsAmount(BigNumDec probability) { if (probability.Equals(0) || probability.Equals(1)) throw new ArgumentException("Probability must be in range (0; 1)"); int iterations = 1; BigNum baseNum = 0.25; while (true) { if (baseNum <= probability) break; baseNum *= 0.25; iterations++; } return iterations; }