diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-11 22:49:16 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2017-10-11 22:49:16 -0300 |
| commit | 8923edffdb36b790014ff47301e53f7ede93ea0d (patch) | |
| tree | e1cff9168eb79110a8832249d208f2978f549a04 /base/src/main/java/bjc/utils/gen/WeightedRandom.java | |
| parent | 946cab444bc301d8a7c756a1bab039558288de89 (diff) | |
Cleanup more
Diffstat (limited to 'base/src/main/java/bjc/utils/gen/WeightedRandom.java')
| -rw-r--r-- | base/src/main/java/bjc/utils/gen/WeightedRandom.java | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/base/src/main/java/bjc/utils/gen/WeightedRandom.java b/base/src/main/java/bjc/utils/gen/WeightedRandom.java index 18225ef..abba36a 100644 --- a/base/src/main/java/bjc/utils/gen/WeightedRandom.java +++ b/base/src/main/java/bjc/utils/gen/WeightedRandom.java @@ -15,32 +15,25 @@ import bjc.utils.funcdata.IList; * @author ben * * @param <E> - * The type of values that are randomly selected. + * The type of values that are randomly selected. */ public class WeightedRandom<E> { - /* - * The list of probabilities for each result - */ + /* The list of probabilities for each result */ private final IList<Integer> probabilities; - - /* - * The list of possible results to pick from - */ + /* The list of possible results to pick from */ private final IList<E> results; - /* - * The source for any needed random numbers - */ + /* The source for any needed random numbers */ private final Random source; - + /* The total chance for all values. */ private int totalChance; /** * Create a new weighted random generator with the specified source of - * randomness + * randomness. * * @param src - * The source of randomness to use. + * The source of randomness to use. */ public WeightedRandom(final Random src) { probabilities = new FunctionalList<>(); @@ -55,9 +48,10 @@ public class WeightedRandom<E> { * Add a probability for a specific result to be given. * * @param chance - * The chance to get this result. + * The chance to get this result. + * * @param result - * The result to get when the chance comes up. + * The result to get when the chance comes up. */ public void addProbability(final int chance, final E result) { probabilities.add(chance); @@ -69,11 +63,12 @@ public class WeightedRandom<E> { /** * Generate a weighted random value. * - * @return A random value selected in a weighted fashion. + * @return + * A random value selected in a weighted fashion. */ public E generateValue() { - final IHolder<Integer> value = new Identity<>(source.nextInt(totalChance)); - final IHolder<E> current = new Identity<>(); + final IHolder<Integer> value = new Identity<>(source.nextInt(totalChance)); + final IHolder<E> current = new Identity<>(); final IHolder<Boolean> picked = new Identity<>(true); probabilities.forEachIndexed((index, probability) -> { @@ -94,7 +89,8 @@ public class WeightedRandom<E> { /** * Return a list of values that can be generated by this generator * - * @return A list of all the values that can be generated + * @return + * A list of all the values that can be generated */ public IList<E> getResults() { return results; @@ -104,7 +100,8 @@ public class WeightedRandom<E> { * 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 + * @return + * A list of pairs of values and value probabilities */ public IList<IPair<Integer, E>> getValues() { return probabilities.pairWith(results); |
