Package net.sf.freecol.common.util
Class RandomChoice<T>
- java.lang.Object
-
- net.sf.freecol.common.util.RandomChoice<T>
-
public class RandomChoice<T> extends java.lang.Object
A class to provide flat and weighted random selection from a collection.
-
-
Field Summary
Fields Modifier and Type Field Description private T
object
private int
probability
-
Constructor Summary
Constructors Constructor Description RandomChoice(T object, int probability)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description T
getObject()
int
getProbability()
static <T> int
getTotalProbability(java.util.Collection<RandomChoice<T>> input)
static <T> T
getWeightedRandom(java.util.logging.Logger logger, java.lang.String logMe, java.util.Collection<RandomChoice<T>> input, java.util.Random random)
static <T> T
getWeightedRandom(java.util.logging.Logger logger, java.lang.String logMe, java.util.stream.Stream<RandomChoice<T>> input, java.util.Random random)
static <T> void
normalize(java.util.Collection<RandomChoice<T>> input, int expectedTotal)
private static <T> T
select(java.util.Collection<RandomChoice<T>> input, int probability)
-
-
-
Field Detail
-
probability
private int probability
-
object
private final T object
-
-
Constructor Detail
-
RandomChoice
public RandomChoice(T object, int probability)
-
-
Method Detail
-
getProbability
public int getProbability()
-
getObject
public T getObject()
-
select
private static <T> T select(java.util.Collection<RandomChoice<T>> input, int probability)
-
getTotalProbability
public static <T> int getTotalProbability(java.util.Collection<RandomChoice<T>> input)
-
getWeightedRandom
public static <T> T getWeightedRandom(java.util.logging.Logger logger, java.lang.String logMe, java.util.Collection<RandomChoice<T>> input, java.util.Random random)
-
getWeightedRandom
public static <T> T getWeightedRandom(java.util.logging.Logger logger, java.lang.String logMe, java.util.stream.Stream<RandomChoice<T>> input, java.util.Random random)
-
normalize
public static <T> void normalize(java.util.Collection<RandomChoice<T>> input, int expectedTotal)
-
-