Java examples for java.util:Random
Returns a value between value1 and value2 that can include value1, but not value2
//package com.java2s; import java.util.Random; public class Main { private static final Random RANDOM = new Random(); /**//from ww w .j a va 2s .c o m * Returns a value between value1 and value2 that can include value1, but not value2 * * @param value1 First value * @param value2 Second value * @return a value between value1 and value2 that can include value1, but not value2 */ public static double randomRangeDoubleExclusive(double value1, double value2) { double min = Math.min(value1, value2); double max = Math.max(value1, value2); double value = min + RANDOM.nextDouble() * (max - min); return Math.min(Math.max(value, min), max - 1); } }