package net.glowstone.util;

import java.util.Random;

public final class WeightedRandom {

    public static <T extends Choice> T getRandom(Random random, Iterable<T> possibilities) {
        int weights = 0;
        for (T possibility : possibilities) {
            weights += possibility.getWeight();
        }

        int restWeight = random.nextInt(weights);

        for (T t : possibilities) {
            restWeight -= t.getWeight();
            if (restWeight < 0) {
                return t;
            }
        }

        return null;
    }

    public interface Choice {

        int getWeight();
    }
}

@@ -81,24 +81,296 @@
 edRandom %7B%0A%0A
+    /**%0A     * Selects a random item from a weighted distribution.%0A     *%0A     * @param random the PRNG to use%0A     * @param possibilities the distribution to sample from%0A     * @param %3CT%3E the type of each of the %7B@code possibilities%7D%0A     * @return a random item%0A     */%0A
     public s
@@ -784,33 +784,32 @@
     %7D%0A        %7D%0A
-%0A
         return n
@@ -816,24 +816,49 @@
 ull;%0A    %7D%0A%0A
+    @FunctionalInterface%0A
     public i

Fix CheckStyle issues in util/WeightedRandom.java (#755)