nextBool method

  1. @override
bool nextBool()
override

Generates a random boolean value.

Example:

var boolValue = Random().nextBool(); // true or false, with equal chance.

Implementation

@override
bool nextBool() {
  // we're returning bits from higher to lower
  if (boolCache_prevShift == 0) {
    boolCache = nextRaw64();
    boolCache_prevShift = 63;
    return boolCache < 0; // for the signed integer negative = highest bit set
  } else {
    assert(boolCache_prevShift > 0);
    boolCache_prevShift--;
    final result = (boolCache & (1 << boolCache_prevShift)) != 0;
    return result;
  }
}