nextBetween method

int nextBetween(
  1. int low,
  2. int high
)

Generates a 32-bit bit random number between low and high, inclusive.

Implementation

int nextBetween(int low, int high) {
  if (low == high) {
    return low;
  }
  if (low > high) {
    int t = low;
    low = high;
    high = t;
  }
  return (nextInt() % (high - low)) + low;
}