nextDouble method

  1. @override
double nextDouble()
override

Generates a non-negative random floating point value uniformly distributed in the range from 0.0, inclusive, to 1.0, exclusive.

Example:

var doubleValue = Random().nextDouble(); // Value is >= 0.0 and < 1.0.
doubleValue = Random().nextDouble() * 256; // Value is >= 0.0 and < 256.0.

Implementation

@override
double nextDouble() {
  while (true) {
    final a = (_bit20 - 1) & nextUint32();
    final b = nextUint32();
    final x = (a * _bit32 + b) / _bit52;
    if (x >= 0.0 && x < 1.0) {
      return x;
    }
    // This should never happen,
    // but we will just generate another pair if it does.
    assert(false);
  }
}