Java Random doubles() Method
SyntaxParameterstreamSize- the number of values to generate randomNumberOrigin- the origin of each random value randomNumberBound- the bound of each random value Return ValueThe doubles() method returns :
ThrowsIllegalArgumentException: if streamSize is a negative value. IllegalArgumentException: if randomNumberOrigin is greater than or equal to randomNumberBound. Example 1Output: Example 2Output: Example 3Output: Exception in thread "main" java.lang.IllegalArgumentException: bound must be greater than origin atjava.util.Random.doubles(Random.java:983) at com.javaTpoint.JavaRandomDoublesExample3.main(JavaRandomDoublesExample3.java:14) If randonNumberOrigin is greater than or equal to randomNumberBound, it will always give you the above-described runtime error, i.e., IllegalArgumentException. Example 4Output: Example 5Output: Exception in thread "main" java.lang.IllegalArgumentException: size must be non-negative atjava.util.Random.doubles(Random.java:887) at com.javaTpoint.JavaRandomDoublesExample5.main(JavaRandomDoublesExample5.java:14) If streamSize is less than zero, it will give you IllegalArgumentException, as described above. Next TopicJava-random-nextboolean-method |