I am generating a large BigInt and need to test whether it is a prime number or not. However, this simple algorithm takes way to long.
bool _isProbablePrime(BigInt n) {
var _isPrime = true;
for (var i = BigInt.from(2); i < (n); i = i + BigInt.one) {
if (n % i == BigInt.zero) _isPrime = false;
}
return _isPrime;
}
Is there another more efficient algorithm that has a fairly high certainty of correctly checking the primality of n?
Any help is appreciated, and thanks in advance! :D