Android examples for java.util:Random Double
Returns a random double between MIN inclusive and MAX inclusive.
//package com.java2s; import java.util.Random; public class Main { /**//from w w w .java 2 s .c om * Returns a random double between MIN inclusive and MAX inclusive. * @param min * value inclusive * @param max * value inclusive * @return an int between 0 inclusive and MAX exclusive. */ public static double getRandomDoubleWithinRange(double min, double max) { if (min == max) { return max; } if (max < min) { double temp = max; max = min; min = temp; } Random r = new Random(); return min + (max - min) * r.nextDouble(); } }