Class RandomUtils
- java.lang.Object
-
- org.apache.commons.lang3.RandomUtils
-
public class RandomUtils extends java.lang.ObjectUtility library that supplements the standard
EaglercraftRandomclass.Caveat: Instances of
EaglercraftRandomare not cryptographically secure.Please note that the Apache Commons project provides a component dedicated to pseudo-random number generation, namely Commons RNG, that may be a better choice for applications with more stringent requirements (performance and/or correctness).
- Since:
- 3.3
-
-
Constructor Summary
Constructors Constructor Description RandomUtils()RandomUtilsinstances should NOT be constructed in standard programming.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleannextBoolean()Returns a random boolean valuestatic byte[]nextBytes(int count)Creates an array of random bytes.static doublenextDouble()Returns a random double within 0 - Double.MAX_VALUEstatic doublenextDouble(double startInclusive, double endExclusive)Returns a random double within the specified range.static floatnextFloat()Returns a random float within 0 - Float.MAX_VALUEstatic floatnextFloat(float startInclusive, float endExclusive)Returns a random float within the specified range.static intnextInt()Returns a random int within 0 - Integer.MAX_VALUEstatic intnextInt(int startInclusive, int endExclusive)Returns a random integer within the specified range.static longnextLong()Returns a random long within 0 - Long.MAX_VALUEstatic longnextLong(long startInclusive, long endExclusive)Returns a random long within the specified range.
-
-
-
Method Detail
-
nextBoolean
public static boolean nextBoolean()
Returns a random boolean value
- Returns:
- the random boolean
- Since:
- 3.5
-
nextBytes
public static byte[] nextBytes(int count)
Creates an array of random bytes.
- Parameters:
count- the size of the returned array- Returns:
- the random byte array
- Throws:
java.lang.IllegalArgumentException- ifcountis negative
-
nextInt
public static int nextInt(int startInclusive, int endExclusive)Returns a random integer within the specified range.
- Parameters:
startInclusive- the smallest value that can be returned, must be non-negativeendExclusive- the upper bound (not included)- Returns:
- the random integer
- Throws:
java.lang.IllegalArgumentException- ifstartInclusive > endExclusiveor ifstartInclusiveis negative
-
nextInt
public static int nextInt()
Returns a random int within 0 - Integer.MAX_VALUE
- Returns:
- the random integer
- Since:
- 3.5
- See Also:
nextInt(int, int)
-
nextLong
public static long nextLong(long startInclusive, long endExclusive)Returns a random long within the specified range.
- Parameters:
startInclusive- the smallest value that can be returned, must be non-negativeendExclusive- the upper bound (not included)- Returns:
- the random long
- Throws:
java.lang.IllegalArgumentException- ifstartInclusive > endExclusiveor ifstartInclusiveis negative
-
nextLong
public static long nextLong()
Returns a random long within 0 - Long.MAX_VALUE
- Returns:
- the random long
- Since:
- 3.5
- See Also:
nextLong(long, long)
-
nextDouble
public static double nextDouble(double startInclusive, double endExclusive)Returns a random double within the specified range.
- Parameters:
startInclusive- the smallest value that can be returned, must be non-negativeendExclusive- the upper bound (not included)- Returns:
- the random double
- Throws:
java.lang.IllegalArgumentException- ifstartInclusive > endExclusiveor ifstartInclusiveis negative
-
nextDouble
public static double nextDouble()
Returns a random double within 0 - Double.MAX_VALUE
- Returns:
- the random double
- Since:
- 3.5
- See Also:
nextDouble(double, double)
-
nextFloat
public static float nextFloat(float startInclusive, float endExclusive)Returns a random float within the specified range.
- Parameters:
startInclusive- the smallest value that can be returned, must be non-negativeendExclusive- the upper bound (not included)- Returns:
- the random float
- Throws:
java.lang.IllegalArgumentException- ifstartInclusive > endExclusiveor ifstartInclusiveis negative
-
nextFloat
public static float nextFloat()
Returns a random float within 0 - Float.MAX_VALUE
- Returns:
- the random float
- Since:
- 3.5
- See Also:
nextFloat(float, float)
-
-