diff options
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java index 4313360..4b0c276 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java +++ b/BJC-Utils2/src/main/java/bjc/utils/gen/WeightedRandom.java @@ -6,23 +6,38 @@ import bjc.utils.data.GenHolder; import bjc.utils.data.Pair; /** - * Represents a random number generator where certain results are weighted more heavily than - * others. + * Represents a random number generator where certain results are weighted + * more heavily than others. + * * @author ben * - * @param <E> The type of values that are randomly selected. + * @param <E> + * The type of values that are randomly selected. */ public class WeightedRandom<E> { - private Random src; - + /** + * The list of probabilities for each result + */ private FunctionalList<Integer> probs; + + /** + * The list of possible results to pick from + */ private FunctionalList<E> results; - private int totalChance; + /** + * The source for any needed random numbers + */ + private Random src; + + private int totalChance; /** - * Create a new weighted random generator with the specified source of randomness - * @param sr The source of randomness to use. + * Create a new weighted random generator with the specified source of + * randomness + * + * @param sr + * The source of randomness to use. */ public WeightedRandom(Random sr) { probs = new FunctionalList<>(); @@ -33,8 +48,11 @@ public class WeightedRandom<E> { /** * Add a probability for a specific result to be given. - * @param chance The chance to get this result. - * @param res The result to get when the chance comes up. + * + * @param chance + * The chance to get this result. + * @param res + * The result to get when the chance comes up. */ public void addProb(int chance, E res) { probs.add(chance); @@ -45,6 +63,7 @@ public class WeightedRandom<E> { /** * Generate a weighted random value. + * * @return A random value selected in a weighted fashion. */ public E genVal() { @@ -65,21 +84,23 @@ public class WeightedRandom<E> { return res.held; } - - /** - * Return a list containing values that can be generated paired - * with the probability of those values being generated - * @return A list of pairs of values and value probabilities - */ - public FunctionalList<Pair<Integer, E>> getValues() { - return probs.pairWith(results); - } /** * Return a list of values that can be generated by this generator + * * @return A list of all the values that can be generated */ public FunctionalList<E> getResults() { return results; } + + /** + * Return a list containing values that can be generated paired with + * the probability of those values being generated + * + * @return A list of pairs of values and value probabilities + */ + public FunctionalList<Pair<Integer, E>> getValues() { + return probs.pairWith(results); + } } |
