Discretize the given value
@param value the value to discretize
@param min the min of the distribution
@param max the max of the distribution
@param binCount the number of bins
@return the discretized value
515297
public static int discretize(double value, double min, double max, int binCount) {
        int discreteValue = (int) (binCount * normalize(value, min, max));
        return clamp(discreteValue, 0, binCount - 1);
    }
575077
function (value, min, max) {
            if (min > max) {
                max = min + max;
                min = max - min;
                max = max - min;
            }
            return Math.min(max, Math.max(min, value));
        }
214119
public static double[] breaks(double min, double max, double h) {
        if (h <= 0.0) {
            throw new IllegalArgumentException("Invalid bin width: " + h);
        }

        if (min > max) {
            throw new IllegalArgumentException("Invalid lower and upper bounds: " + min + " > " + max);
        }
        
        int k = (int) Math.ceil((max-min) / h);
        double[] breaks = new double[k + 1];
        
        breaks[0] = min - (h * k - (max - min)) / 2;
        breaks[k] = max + (h * k - (max - min)) / 2;
        for (int i = 1; i < k; i++) {
            breaks[i] = breaks[i - 1] + h;
        }
        
        return breaks;
    }
321224
public static final double keepIn(double value, double min, double max) {
        return Math.max(min, Math.min(value, max));
    }
928155
public static int nextInt(Random random, int min, int max) {
		Validate.isTrue(max >= min, "Start value must be smaller or equal to end value.");
		MoreValidate.nonNegative("min", min);

		if (min == max) {
			return min;
		}

		return min + random.nextInt(max - min);
	}
394517
public static double uniform(Random rng, double min, double max) {
        return rng.nextDouble() * (max - min) + min;
    }
930348
private void setNumberHits(BitSet bits, String value, int min, int max) {
        String[] fields = StringUtils.delimitedListToStringArray(value, ",");
        for (String field : fields) {
            if (!field.contains("/")) {
                // Not an incrementer so it must be a range (possibly empty)
                int[] range = getRange(field, min, max);
                bits.set(range[0], range[1] + 1);
            } else {
                String[] split = StringUtils.delimitedListToStringArray(field, "/");
                if (split.length > 2) {
                    throw new IllegalArgumentException("Incrementer has more than two fields: '" + field
                            + "' in expression \"" + this.expression + "\"");
                }
                int[] range = getRange(split[0], min, max);
                if (!split[0].contains("-")) {
                    range[1] = max - 1;
                }
                int delta = Integer.valueOf(split[1]);
                for (int i = range[0]; i <= range[1]; i += delta) {
                    bits.set(i);
                }
            }
        }
    }
605272
public ValidatorBuilderInteger<PARENT> range(int min, int max) {

    return range(new Range<>(Integer.valueOf(min), Integer.valueOf(max)));
  }
588145
public static double random(double min, double max) {
        assert max > min;
        return min + Math.random() * (max - min);
    }
409724
protected static <A> int[] discretize(NumberArrayAdapter<?, A> adapter, A data, final int len, final int bins) {
    double min = adapter.getDouble(data, 0), max = min;
    for(int i = 1; i < len; i++) {
      double v = adapter.getDouble(data, i);
      if(v < min) {
        min = v;
      }
      else if(v > max) {
        max = v;
      }
    }
    final double scale = (max > min) ? bins / (max - min) : 1;
    int[] discData = new int[len];
    for(int i = 0; i < len; i++) {
      int bin = (int) Math.floor((adapter.getDouble(data, i) - min) * scale);
      discData[i] = bin < 0 ? 0 : bin >= bins ? bins - 1 : bin;
    }
    return discData;
  }
792945
public static BigRational min(BigRational... values) {
		if (values.length == 0) {
			return BigRational.ZERO;
		}
		BigRational result = values[0];
		for (int i = 1; i < values.length; i++) {
			result = result.min(values[i]);
		}
		return result;
	}
1166512
public static int getMinValue (int[] values)
    {
        int min = Integer.MAX_VALUE;
        int vcount = (values == null) ? 0 : values.length;
        for (int ii = 0; ii < vcount; ii++) {
            if (values[ii] < min) {
                // new min
                min = values[ii];
            }
        }
        return min;
    }
624466
@Override
	public void aggregate(T value) {

		if (value == null) {
			nullCount++;
		}
		else if (isNan(value)) {
			nanCount++;
		}
		else if (isInfinite(value)) {
			infinityCount++;
		}
		else {
			nonMissingCount++;

			min.aggregate(value);
			max.aggregate(value);
			sum.aggregate(value);

			double doubleValue = value.doubleValue();
			double delta = doubleValue - mean.value();
			mean = mean.add(delta / nonMissingCount);
			m2 = m2.add(delta * (doubleValue - mean.value()));
		}
	}
1149681
protected ValueList generateNumbers(int min, int max, Context ctxt)
			throws ValueException
	{
		ValueList list = new ValueList();
		for (int i = min; i < max + 1; i++)
		{
			list.add(NumericValue.valueOf(i, ctxt));
		}

		return list;
	}
306409
public static DoubleUnaryOperator interpolate(
        final double min, final double max)
    {
        final double delta = max - min;
        return x -> min + x * delta;
    }
430153
public double getDouble(final double min, final double max) {
		return min(min, max) + getDouble(abs(max - min));
	}
132580
public ValidatorBuilderBigDecimal<PARENT> range(BigDecimal min, BigDecimal max) {

    return range(new Range<>(min, max));
  }