Who wants to help me with my homework?
I\'m try to implement Fermat\'s primality test in Java using BigIntegers. My implementation is as follows, but unfortunately i
a should be "pick a randomly in the range (1, n − 1]" and I don't really see that happening. You could print a to check that.
As for how to do that:
BigInteger a = BigInteger.valueOf(random.nextInt(n-2)+2);
e.g. You shouldn't use the BigInteger constructor with a Random argument; that's just a source of randomness, but a should be a random value.
The 'random.nextInt(n-1)+1' comes from the definition of nextInt which, given argument k, returns a random value 0 up to and including k-1. And you want a to be larger than 1 and smaller than n.