Here you can find the source of randomDouble(double minDouble, double maxDouble)
public static double randomDouble(double minDouble, double maxDouble)
//package com.java2s; //License from project: Apache License import java.text.DecimalFormat; import java.util.Random; public class Main { private static final ThreadLocal<Random> localRandom = new ThreadLocal<Random>() { @Override/*from w w w .java2 s . c o m*/ protected Random initialValue() { return new Random(); } }; public static double randomDouble(double minDouble, double maxDouble) { return minDouble == maxDouble ? minDouble : randomInt((int) getCorrectionValue(minDouble * 100000, 0), (int) getCorrectionValue(maxDouble * 100000, 0)) / 100000.0; } public static double randomDouble() { return localRandom.get().nextDouble(); } public static int randomInt(int minInt, int maxInt) { return minInt == maxInt ? minInt : (Math.min(minInt, maxInt) + localRandom.get().nextInt(Math.abs(maxInt - minInt) + 1)); } public static double getCorrectionValue(double basicValue, int digit) { if (digit < 0) return basicValue; StringBuilder sb = new StringBuilder("#"); if (digit > 0) { sb.append("0."); for (int i = 0; i < digit; i++) { sb.append("0"); } } DecimalFormat format = new DecimalFormat(sb.toString()); return Double.parseDouble(format.format(basicValue)); } public static Number min(Number... numbers) { Number min = Double.MAX_VALUE; for (Number number : numbers) { if (number.doubleValue() < min.doubleValue()) { min = number; } } return min; } public static int nextInt() { return localRandom.get().nextInt(); } public static int nextInt(int n) { return localRandom.get().nextInt(n); } }