nextDouble is a static method of the RandomUtils class that will return a random double value.
RandomUtilsRandomUtils is defined in the Apache Commons Lang package. Apache Commons Lang can be added to the Maven project by adding the following dependency to the pom.xml file.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
For other versions of the
commons-langpackage, refer to the Maven Repository.
public static double nextDouble()
The nextDouble method does not take a parameter.
This method returns a random double value.
The returned random double value will be within the range of
0toDouble.MAX_VALUE.
In the code below, we use the nextDouble method.
import org.apache.commons.lang3.RandomUtils;class NextDoubleExample {public static void main( String args[] ) {System.out.println("RandomUtils.nextDouble() => " + RandomUtils.nextDouble()); // random double valueSystem.out.println("RandomUtils.nextDouble() => " + RandomUtils.nextDouble()); // random double value}}
In the code above:
RandomUtils class.import org.apache.commons.lang3.RandomUtils;
nextDouble method to get the random double value.103
500
The output above may vary whenever the code is run. This is because every time, a random number is going to be generated.