我正在使用BigInteger類來隨機生成一個大素數,但我不斷得到負值。如何忽略所有的負面回報?我應該如何修復10號碼?如何忽略隨機數發生器中的負值
public class Gen{
public static void main(String[] args) throws IOException {
Random rand = new SecureRandom();
BigInteger.probablePrime(100, rand);
System.out.println(BigInteger.probablePrime(100, rand).longValue());
}
}
什麼是'rann'?你的意思是'rand'? – 2013-05-05 08:33:26
你不能使用Math.abs嗎? – 2013-05-05 08:34:08
「*返回一個**肯定的** BigInteger,可能是素數*」 - 你如何得到一個負數?你確定你在看正確的輸出嗎? – Maroun 2013-05-05 08:34:29