Class Random

java.lang.Object
dev.twilite.game.common.Random

public class Random extends Object
Convenience helpers for thread-local random values.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Returns a random boolean.
    static double
    Returns a random double from 0.0, inclusive, to 1.0, exclusive.
    static double
    nextDouble(double min, double max)
    Returns a random double from min, inclusive, to max, exclusive.
    static double
    Returns a normally distributed value with mean 0.0 and standard deviation 1.0.
    static double
    nextGaussian(double mean, double standardDeviation)
    Returns a normally distributed value with the supplied mean and standard deviation.
    static int
    Returns a random integer across the full int range.
    static int
    nextInt(int max)
    Returns a random integer from 0, inclusive, to max, exclusive.
    static int
    nextInt(int min, int max)
    Returns a random integer from min, inclusive, to max, exclusive.
    static double
    nextLogNormal(double median, double sigma)
    Returns a log-normally distributed value.
    static int
    nextValue(int[] values)
    Returns a random integer array element.
    static <T> T
    nextValue(Collection<T> values)
    Returns a random collection element, or null when the collection is empty.
    static <T> T
    nextValue(T[] elements)
    Returns a random array element, or null when the array is empty.
    static <T> T
    nextValue(T[] elements, T fallback)
    Returns a random array element, or defaultValue when the array is empty.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Random

      public Random()
  • Method Details

    • nextInt

      public static int nextInt()
      Returns a random integer across the full int range.
    • nextInt

      public static int nextInt(int max)
      Returns a random integer from 0, inclusive, to max, exclusive.
    • nextInt

      public static int nextInt(int min, int max)
      Returns a random integer from min, inclusive, to max, exclusive.

      If the bounds are equal, that value is returned.

    • nextBoolean

      public static boolean nextBoolean()
      Returns a random boolean.
    • nextDouble

      public static double nextDouble()
      Returns a random double from 0.0, inclusive, to 1.0, exclusive.
    • nextDouble

      public static double nextDouble(double min, double max)
      Returns a random double from min, inclusive, to max, exclusive.

      If the bounds are equal, that value is returned.

    • nextGaussian

      public static double nextGaussian()
      Returns a normally distributed value with mean 0.0 and standard deviation 1.0.
    • nextGaussian

      public static double nextGaussian(double mean, double standardDeviation)
      Returns a normally distributed value with the supplied mean and standard deviation.
    • nextLogNormal

      public static double nextLogNormal(double median, double sigma)
      Returns a log-normally distributed value.
    • nextValue

      public static <T> T nextValue(T[] elements, T fallback)
      Returns a random array element, or defaultValue when the array is empty.
    • nextValue

      public static <T> T nextValue(T[] elements)
      Returns a random array element, or null when the array is empty.
    • nextValue

      public static <T> T nextValue(Collection<T> values)
      Returns a random collection element, or null when the collection is empty.
    • nextValue

      public static int nextValue(int[] values)
      Returns a random integer array element.