Class FastRandomUtils

java.lang.Object
ovh.paulem.arcana.math.FastRandomUtils

public class FastRandomUtils extends Object
Utility class for generating random values using FastRandom.
This class provides methods for generating random booleans, bytes, integers, longs, doubles, and floats with optional range constraints and probability checks.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    doubleProbability(double probability)
    Determines if an event occurs based on a given probability (double).
    static boolean
    floatProbability(float probability)
    Determines if an event occurs based on a given probability (float).
    This method is less precise than doubleProbability(double), but consumes less memory
    static boolean
    Generates a random boolean value.
    Can be used to simulate a coin flip or other random boolean events.
    static byte[]
    nextBytes(int count)
    Generates an array of random bytes.
    static double
    Generates a random double within the range [0.0, Double.MAX_VALUE).
    static double
    nextDouble(double startInclusive, double endExclusive)
    Generates a random double within a specified range.
    static float
    Generates a random float within the range [0.0, Float.MAX_VALUE).
    static float
    nextFloat(float startInclusive, float endExclusive)
    Generates a random float within a specified range.
    static int
    Generates a random integer within the range [0, Integer.MAX_VALUE).
    static int
    nextInt(int startInclusive, int endExclusive)
    Generates a random integer within a specified range.
    static long
    Generates a random long within the range [0, Long.MAX_VALUE).
    static long
    nextLong(long startInclusive, long endExclusive)
    Generates a random long within a specified range.

    Methods inherited from class java.lang.Object

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

    • FastRandomUtils

      public FastRandomUtils()
  • Method Details

    • floatProbability

      public static boolean floatProbability(float probability)
      Determines if an event occurs based on a given probability (float).
      This method is less precise than doubleProbability(double), but consumes less memory
      Parameters:
      probability - the probability of the event occurring (0.0 to 1.0)
      Returns:
      true if the event occurs, false otherwise
      Throws:
      IllegalArgumentException - if the probability is negative or greater than 1
    • doubleProbability

      public static boolean doubleProbability(double probability)
      Determines if an event occurs based on a given probability (double).
      Parameters:
      probability - the probability of the event occurring (0.0 to 1.0)
      Returns:
      true if the event occurs, false otherwise
      Throws:
      IllegalArgumentException - if the probability is negative or greater than 1
    • nextBoolean

      public static boolean nextBoolean()
      Generates a random boolean value.
      Can be used to simulate a coin flip or other random boolean events.
      Returns:
      a random boolean
    • nextBytes

      public static byte[] nextBytes(int count)
      Generates an array of random bytes.
      Parameters:
      count - the number of random bytes to generate
      Returns:
      an array of random bytes
      Throws:
      IllegalArgumentException - if the count is negative
    • nextInt

      public static int nextInt(int startInclusive, int endExclusive)
      Generates a random integer within a specified range.
      Parameters:
      startInclusive - the inclusive lower bound of the range
      endExclusive - the exclusive upper bound of the range
      Returns:
      a random integer within the range
      Throws:
      IllegalArgumentException - if the range is invalid or negative
    • nextInt

      public static int nextInt()
      Generates a random integer within the range [0, Integer.MAX_VALUE).
      Returns:
      a random integer
    • nextLong

      public static long nextLong(long startInclusive, long endExclusive)
      Generates a random long within a specified range.
      Parameters:
      startInclusive - the inclusive lower bound of the range
      endExclusive - the exclusive upper bound of the range
      Returns:
      a random long within the range
      Throws:
      IllegalArgumentException - if the range is invalid or negative
    • nextLong

      public static long nextLong()
      Generates a random long within the range [0, Long.MAX_VALUE).
      Returns:
      a random long
    • nextDouble

      public static double nextDouble(double startInclusive, double endExclusive)
      Generates a random double within a specified range.
      Parameters:
      startInclusive - the inclusive lower bound of the range
      endExclusive - the exclusive upper bound of the range
      Returns:
      a random double within the range
      Throws:
      IllegalArgumentException - if the range is invalid or negative
    • nextDouble

      public static double nextDouble()
      Generates a random double within the range [0.0, Double.MAX_VALUE).
      Returns:
      a random double
    • nextFloat

      public static float nextFloat(float startInclusive, float endExclusive)
      Generates a random float within a specified range.
      Parameters:
      startInclusive - the inclusive lower bound of the range
      endExclusive - the exclusive upper bound of the range
      Returns:
      a random float within the range
      Throws:
      IllegalArgumentException - if the range is invalid or negative
    • nextFloat

      public static float nextFloat()
      Generates a random float within the range [0.0, Float.MAX_VALUE).
      Returns:
      a random float