How can I generate a random BigInteger within a certain range?

后端 未结 6 2414
春和景丽
春和景丽 2021-02-13 06:52

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;
}
         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-13 07:45

    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);
    }
    

提交回复
热议问题