public class RandomItemSelector extends Object
| Constructor and Description |
|---|
RandomItemSelector() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
getRandom(List<T> items)
Returns a random item from the given list
|
static <T> T |
getRandom(Map<?,T> items)
Returns are random value from the given map
|
static <T> T |
getSpecificRandom(Map<T,Float> items)
Wrapper for
getSpecificRandom(java.util.Map, int). |
static <T> T |
getSpecificRandom(Map<T,Float> items,
int resolution)
This method accepts a map of items and a float value.
|
public static <T> T getRandom(List<T> items)
T - type of the itemsitems - sourcepublic static <T> T getRandom(Map<?,T> items)
T - type of the items (values)items - sourcepublic static <T> T getSpecificRandom(Map<T,Float> items)
getSpecificRandom(java.util.Map, int).
Uses default resolution of 100, this means the lowest possible
percentage for each item is 1% or 0.01T - type of the itemsitems - items and their probabilitygetSpecificRandom(java.util.Map, int)public static <T> T getSpecificRandom(Map<T,Float> items, int resolution)
getRandom(java.util.List), but now
you can define a probability for each item. This float value should be
in the interval of [0,1], where 0 is 0% and 1 is 100%
The resolution parameter defines how fine the percentage can be.
For example: with a resolution of 100, the lowest percentage can be 1% and
with 100 0.1% and so forth.
NOTE: This method works by creating a List of the size of the resolution. Therefor
large resolutions will create large lists on the heap!T - type of the itemsitems - items and their probabilityresolution - resolution the random gettingCopyright © 2015. All rights reserved.