To generate random integers within a specific range, I have tried the code given below.
public class RandomIntegers {
public static void main(String[] args) {
System.out.println("Double between 5.0 and 10.00: RandomDoubleNumber = "+getRandomDoubleBetweenRange(10.0, 100.00));
}
private static double getRandomDoubleBetweenRange(double min, double max) {
double x = (Math.random()*((max-min)+1))+min;
return x;
}
}
Output of this code is: Double between 5.0 and 10.00: RandomDoubleNumber = 68.11912269349051
Hope this helps!
Join our Java online course and learn more about Java.
Thanks!