Consider this method that works well:
public static bool mightBePrime(int N) {
BigInteger a = rGen.Next (1, N-1);
return modExp (a, N - 1, N) == 1;
}
Now, in order to fulfill a requirement of the class I'm taking, mightBePrime
must accept a BigInteger
N, but that means that I need a different way to generate my random BigInteger
a
.
My first idea was to do something like BigInteger a = (N-1) * rGen.NextDouble ()
, but a BigInteger
can't be multiplied by a double
.
How can I generate a random BigInteger
between 1 and N-1, where N is a BigInteger
?