Class RandomGenerator


  • public class RandomGenerator
    extends java.lang.Object
    Utility class to help with random numbers. This class should be used instead of Math.random() and similar methods, as using class allows for "fake" random numbers that ensure deterministic behavior.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean chance​(float n)
      Produces a random float between 0.0 and 1.0, then compares that number against n and returns the result.
      static float getFloat​(float min, float max)
      Returns a random float somewhere in the range between the minimum (inclusive) and maximum (exclusive).
      static int getInt​(int min, int max)
      Returns a random integer somewhere in the range between the minimum (inclusive) and maximum (exclusive).
      static <T> T pick​(java.util.List<T> elements)
      Picks and returns a random element from the specified list.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getInt

        public static int getInt​(int min,
                                 int max)
        Returns a random integer somewhere in the range between the minimum (inclusive) and maximum (exclusive).
      • getFloat

        public static float getFloat​(float min,
                                     float max)
        Returns a random float somewhere in the range between the minimum (inclusive) and maximum (exclusive).
      • chance

        public static boolean chance​(float n)
        Produces a random float between 0.0 and 1.0, then compares that number against n and returns the result. In other words, passing a value of 0.9 against this method will have a 90% chance of returning true.
      • pick

        public static <T> T pick​(java.util.List<T> elements)
        Picks and returns a random element from the specified list.
        Throws:
        java.lang.IllegalArgumentException - if the provided list is empty.