Here you can find the source of getDoubleInRange(double minValue, double maxValue)
Parameter | Description |
---|---|
minValue | The minimum value for the returned value |
maxValue | The maximum value for the returned value |
public static double getDoubleInRange(double minValue, double maxValue)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { /** Random number generator */ private static final Random RANDOM = new Random(); /**/*from ww w. j av a 2s. c o m*/ * It returns a double/Double value between min and max value (included). * * @param minValue * The minimum value for the returned value * @param maxValue * The maximum value for the returned value * @return A double/Double value between min and max value (included) */ public static double getDoubleInRange(double minValue, double maxValue) { // This can happen. It's a way to specify a precise value if (minValue == maxValue) { return minValue; } double retValue; double margin = (maxValue - minValue + 0.1); do { retValue = minValue + RANDOM.nextDouble() * margin; } while (retValue > maxValue); return retValue; } }