nextBigInteger method

  1. @override
BigInt nextBigInteger(
  1. int bitLength
)
override

Get a random BigInteger of bitLength bits.

Implementation

@override
BigInt nextBigInteger(int bitLength) {
  int fullBytes = bitLength ~/ 8;
  BigInt main = numbers.bytesToInt(nextBytes(fullBytes));

  /// forcing remainingBits to be calculate with bitLength
  int remainingBits = (bitLength - main.bitLength);
  int additional = remainingBits < 4
      ? dartRandom.nextInt(pow(2, remainingBits) as int)
      : remainingBits;
  BigInt additionalBit = (new BigInt.from(additional) << (fullBytes * 8));
  BigInt result = main + additionalBit;
  return result;
}