Class RandomKit
java.lang.Object
com.iohao.net.common.kit.RandomKit
Random number generation utilities.
- Author:
- 渔民小镇
- date:
- 2022-07-14
-
Method Summary
Modifier and TypeMethodDescriptionstatic intrandom(int end) Gets a random number within the specified range (0 ~ end)static intrandom(int start, int end) Gets a random number within the specified rangestatic longrandom(long end) Gets a random number within the specified range (0 ~ end)static longrandom(long start, long end) Gets a random number within the specified rangestatic booleanRandomly generates a boolean valuestatic doubleGenerate a random double value in the range [0.0, 1.0).static intrandomEle(int[] array) Select a random element from the given int array.static <T> TrandomEle(@NonNull T[] array) Select a random element from the given array.static <T> TSelect a random element from the given list.static intrandomInt(int limit) Gets a random number within the specified range [0, limit)static intrandomInt(int min, int max) Gets a random number within the specified rangestatic longrandomLong(long limit) Gets a random number within the specified range [0, limit)static longrandomLong(long min, long max) Gets a random number within the specified range
-
Method Details
-
randomInt
public static int randomInt(int limit) Gets a random number within the specified range [0, limit)- Parameters:
limit- The limit of the random number range, exclusive.- Returns:
- The random number.
-
randomInt
public static int randomInt(int min, int max) Gets a random number within the specified range- Parameters:
min- Minimum number (inclusive)max- Maximum number (exclusive)- Returns:
- The random number
-
randomLong
public static long randomLong(long limit) Gets a random number within the specified range [0, limit)- Parameters:
limit- The limit of the random number range, exclusive.- Returns:
- The random number
- Since:
- 21.23
-
randomLong
public static long randomLong(long min, long max) Gets a random number within the specified range- Parameters:
min- Minimum number (inclusive)max- Maximum number (exclusive)- Returns:
- The random number
- Since:
- 21.23
-
random
public static int random(int start, int end) Gets a random number within the specified range- Parameters:
start- Starting value (inclusive)end- Ending value (inclusive)- Returns:
- The random number
-
random
public static int random(int end) Gets a random number within the specified range (0 ~ end)- Parameters:
end- Ending value (inclusive)- Returns:
- The random number
-
random
public static long random(long start, long end) Gets a random number within the specified range- Parameters:
start- Starting value (inclusive)end- Ending value (inclusive)- Returns:
- The random number
- Since:
- 21.23
-
random
public static long random(long end) Gets a random number within the specified range (0 ~ end)- Parameters:
end- Ending value (inclusive)- Returns:
- The random number
- Since:
- 21.23
-
randomBoolean
public static boolean randomBoolean()Randomly generates a boolean value- Returns:
- The boolean value
-
randomEle
Select a random element from the given list.- Type Parameters:
T- the element type- Parameters:
list- the list to pick from- Returns:
- a randomly selected element
-
randomEle
public static <T> T randomEle(@NonNull T[] array) Select a random element from the given array.- Type Parameters:
T- the element type- Parameters:
array- the array to pick from- Returns:
- a randomly selected element
-
randomEle
public static int randomEle(int[] array) Select a random element from the given int array.- Parameters:
array- the int array to pick from- Returns:
- a randomly selected element
-
randomDouble
public static double randomDouble()Generate a random double value in the range [0.0, 1.0).- Returns:
- a random double
-