Class RandomKit
java.lang.Object
com.iohao.net.common.kit.RandomKit
Random number generation utilities.
- Author:
- 渔民小镇
- date:
- 2022-07-14
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintrandom(int end) Gets a random number within the specified range (0 ~ end)intrandom(int start, int end) Gets a random number within the specified rangelongrandom(long end) Gets a random number within the specified range (0 ~ end)longrandom(long start, long end) Gets a random number within the specified rangebooleanRandomly generates a boolean valuedoubleGenerate a random double value in the range [0.0, 1.0).intrandomEle(int[] array) Select a random element from the given int array.<T> TrandomEle(@NonNull T[] array) Select a random element from the given array.<T> TSelect a random element from the given list.intrandomInt(int limit) Gets a random number within the specified range [0, limit)intrandomInt(int min, int max) Gets a random number within the specified rangelongrandomLong(long limit) Gets a random number within the specified range [0, limit)longrandomLong(long min, long max) Gets a random number within the specified range
-
Constructor Details
-
RandomKit
public RandomKit()
-
-
Method Details
-
randomInt
public 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 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 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 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 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 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 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 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 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 <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 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 double randomDouble()Generate a random double value in the range [0.0, 1.0).- Returns:
- a random double
-