|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttoxi.util.datatypes.WeightedRandomSet<T>
public class WeightedRandomSet<T>
This class provides a generic random-weight distribution of arbitary objects.
Add elements with their weight to the set and then use the
getRandom()
method to retrieve objects. The frequency of returned
elements is based on their relative weight. This makes it easy to provide
biased preferences.
http://www.electricmonk.nl/log/2009/12/23/weighted-random-distribution/
Constructor Summary | |
---|---|
WeightedRandomSet()
|
Method Summary | |
---|---|
WeightedRandomSet<T> |
add(T item,
int weight)
Add a new element of type T to the set. |
java.util.List<WeightedRandomEntry<T>> |
getElements()
|
T |
getRandom()
Returns a randomly picked element from the set. |
void |
remove(T item)
Removes the given item from the set. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public WeightedRandomSet()
Method Detail |
---|
public WeightedRandomSet<T> add(T item, int weight)
item
- weight
-
public java.util.List<WeightedRandomEntry<T>> getElements()
public T getRandom()
public void remove(T item)
item
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |