Class RandomUtil
java.lang.Object
ru.progrm_jarvis.javacommons.random.RandomUtil
Utility for getting random values.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TgetRandom(@NonNull Collection<T> values) Gets a random value from the collection specified.static <T> TGets a random value from the list specified.static <T> TGets a random value from the map specified considering chances.static intProvides1or-1randomly.
-
Method Details
-
randomSign
public static int randomSign()Provides1or-1randomly.- Returns:
1or-1
-
getRandom
Gets a random value from the map specified considering chances.- Type Parameters:
T- type of value randomly got- Parameters:
chancedValues- values from which to get a random one the keys of the map are the actual values, the values of the map are the chances- Returns:
- got random value
- Throws:
IllegalArgumentException- ifvalues is empty
-
getRandom
Gets a random value from the list specified.- Type Parameters:
T- type of value randomly got- Parameters:
values- values from which to get a random one- Returns:
- got random value
- Throws:
IllegalArgumentException- ifvalues is empty
-
getRandom
Gets a random value from the collection specified.- Type Parameters:
T- type of value randomly got- Parameters:
values- values from which to get a random one- Returns:
- got random value
- Throws:
IllegalArgumentException- ifvalues is empty
-