round method

int round(
  1. double value
)

Rounds value to a nearby integer, randomly rounding up or down based on the fractional value.

For example, round(3.2) has a 20% chance of returning 3, and an 80% chance of returning 4.

Implementation

int round(double value) {
  var result = value.floor();
  if (float(1.0) < value - result) result++;
  return result;
}