nextBigInteger method

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

Get a random BigInteger of bitLength bits.

Implementation

@override
BigInt nextBigInteger(int bitLength) {
  final fullBytes = bitLength ~/ 8;
  final remainingBits = bitLength % 8;

  // Generate a number from the full bytes. Then, prepend a smaller number
  // covering the remaining bits.
  final main = bytesToUnsignedInt(nextBytes(fullBytes));
  final additional = dartRandom.nextInt(1 << remainingBits);
  return main + (BigInt.from(additional) << (fullBytes * 8));
}