java - 如何指定具有最大位数的 BigInteger 类型的 BigInteger?
问题描述
我知道 BigInteger 有一个构造函数,您可以在其中通过传递新 BigInteger 的最大 bitLength 和一个随机参数来生成一个随机 BigInteger:
BigInteger(int numBits, Random rnd)
如何生成一个随机的 BitInteger,其中 numBits 的类型是 BitInteger 而不是 int?注意:我不想做myBitInteger.intValue()
.
解决方案
你不能。没有构造函数需要BigInteger
多个位。
为什么不?BigInteger
不会在内部将位数存储为大整数。它包含int
许多位,一个反映在公共 API 中的设计决策:
BigInteger(int numBits, Random rnd);
int bitCount();
int bitLength();
static BigInteger probablePrime(int bitLength, Random rnd);
推荐阅读
- javascript - 单击嵌入的 youtube 视频时是否可以触发事件?
- javascript - 谁能解释 this.id 在这里是如何工作的?
- laravel - 如何使用 laravel 5.7 设置 mailgun?
- javascript - 如何使用 Map 对象查找数组的元素计数
- python - 如何使用 selenium 从网站上抓取一些链接
- java - 安装eclipse时缺少JRE
- json - 如何使用 ELK 堆栈将大 JSON 文件导入 Docker-swarm 集群?
- haskell - 如何总结haskell中奇数的索引?
- java - dispatcherServletRegistration Spring 启动异常
- google-sheets - 如何计算 Google 表格中的所有模式?