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; }
Use the Random-Class
public BigInteger getRandom(int length){ Random random = new Random(); byte[] data = new byte[length]; random.NextBytes(data); return new BigInteger(data); }