package com.extrahardmode.service;


import java.util.Random;

/**
 * @author Diemex
 */
public class OurRandom
{
    private static Random rdm;


    public OurRandom()
    {
        rdm = new Random();
    }


    public static double nextDouble()
    {
        return rdm.nextDouble();
    }


    public static int nextInt(int range)
    {
        return rdm.nextInt(range);
    }


    public static boolean percentChance(int percentage)
    {
        return nextInt(100) < percentage;
    }


    /**
     * Get a random index given the weights
     *
     * @param itemWeights list of weights as integers
     *
     * @return the index of the items chosen
     */
    public static int weightedRandom(Integer[] itemWeights)
    {
        // Compute the total weight of all items together
        int totalWeight = 0;
        for (int i : itemWeights)
            totalWeight += i;
        // Now choose a random item
        int randomIndex = -1;
        double random = Math.random() * totalWeight;
        for (int i = 0; i < itemWeights.length; ++i)
        {
            random -= itemWeights[i];
            if (random <= 0.0d)
            {
                randomIndex = i;
                break;
            }
        }
        return randomIndex;
    }


    /**
     * Create a new Random object, call when plugin is enabled to ensure it's fresh etc.
     */
    public static void reload()
    {
        rdm = new Random();
    }
}

@@ -241,32 +241,89 @@
 tDouble()%0A    %7B%0A
+        if (rdm == null)%0A            rdm = new Random();%0A
         return r
@@ -386,32 +386,134 @@
 nt range)%0A    %7B%0A
+        //Dunno where the NPE comes from :'(%0A        if (rdm == null)%0A            rdm = new Random();%0A
         return r
@@ -882,32 +882,89 @@
 mWeights)%0A    %7B%0A
+        if (rdm == null)%0A            rdm = new Random();%0A
         // Compu

Fix NPE in OurRandom, have absolutely no clue where it comes from