Reputation: 663
I know BigInteger has a constructor where you can generate a random BigInteger by passing through the maximum bitLength of the new BigInteger and a random parameter:
BigInteger(int numBits, Random rnd)
How can you generate a random BitInteger where numBits is of type BitInteger not int?
Note: I don't want to do myBitInteger.intValue()
.
Upvotes: 1
Views: 367
Reputation: 361585
You can't. There is no constructor that takes a BigInteger
number of bits.
Why not? BigInteger
doesn't store the number of bits internally as a big integer. It's holds an int
number of bits, a design decision reflected in the public API:
BigInteger(int numBits, Random rnd);
int bitCount();
int bitLength();
static BigInteger probablePrime(int bitLength, Random rnd);
Upvotes: 7