randDouble function

double randDouble(
  1. double min,
  2. double max
)

This method generates and returns a random double from min to max (inclusive).

Implementation

double randDouble(double min, double max) {
  // If `min` and `max` are the same number, just return that number.
  if (min == max) {
    return min;
  }

  // If `min` is greater than `max`, swap their values.
  if (min > max) {
    double temp = min;
    min = max;
    max = temp;
  }

  // Find the random number in the range.
  return (Random().nextDouble() * (max - min)) + min;
}