nextBigInteger method

BigInt nextBigInteger(
  1. int bitLength
)

Implementation

BigInt nextBigInteger(int bitLength) {
  int fullBytes = bitLength ~/ 8;

  /// var remainingBits = bitLength % 8;

  /// Generate a number from the full bytes. Then, prepend a smaller number
  /// covering the remaining bits.
  BigInt main = bytesToInt(nextBytes(fullBytes));

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