Class RandomChoice<T>


  • public class RandomChoice<T>
    extends java.lang.Object
    A class to provide flat and weighted random selection from a collection.
    • 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)