<分区>
我需要得到一个大于 2^511 且小于 2^512 的随机 BigInteger。
<分区>
我需要得到一个大于 2^511 且小于 2^512 的随机 BigInteger。
最佳答案
byte[] bytes = new byte[64]; // 512 bits
new Random().nextBytes(bytes);
bytes[0] |= 0x80; // set the most significant bit
return new BigInteger(1, bytes);
关于java - 获取范围 (x, y) 内的随机 BigInteger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23054262/
相关文章:
java - ActionListener 如何将处理结果发送回 JTextArea
java - Android Studio 中未处理的异常 Class.forname ("com.google.cloud.sql.jdbc.Driver")
python - 如何从 4 个 csv 文件中随机抽样,以便在 Python 中每个 csv 文件中按顺序出现不超过 2/3 行
java - 如何防止在随机 int 中生成值? ( java )
java - 如何在 Spring Boot 应用程序中测试 Quartz 作业的正常工作