Class SolaRandom

java.lang.Object
technology.sola.engine.utils.SolaRandom

@NullMarked public class SolaRandom extends Object
Wrapper around Random that exposes some additional convenience methods. This wrapper will ensure that random number generation will work across different SolaPlatforms.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
     
    static float
     
    static float
    nextFloat(float min, float max)
    Returns a pseudorandom, uniformly distributed float value between min (inclusive) and max value (inclusive)
    static int
    nextInt(int bound)
    Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive)
    static int
    nextInt(int min, int max)
    Returns a pseudorandom, uniformly distributed int value between min (inclusive) and max value (inclusive)
    static float
    noise(float x, float y)
    Generates a Perlin noise value for a 2d time scale.
    static float
    noise(float x, float y, int octaves, float falloff)
    Generates a Perlin noise value for a 2d time scale.
    static void
    setSeed(long seed)
    Sets the seed for random number generation.

    Methods inherited from class java.lang.Object

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

    • setSeed

      public static void setSeed(long seed)
      Sets the seed for random number generation.
      Parameters:
      seed - the seed
    • nextBoolean

      public static boolean nextBoolean()
      Returns:
      the next pseudorandom, uniformly distributed boolean value
    • nextInt

      public static int nextInt(int bound)
      Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive)
      Parameters:
      bound - the exclusive boundary value
      Returns:
      the random int value
    • nextInt

      public static int nextInt(int min, int max)
      Returns a pseudorandom, uniformly distributed int value between min (inclusive) and max value (inclusive)
      Parameters:
      min - the inclusive min value
      max - the inclusive max value
      Returns:
      the random int value
    • nextFloat

      public static float nextFloat()
      Returns:
      a pseudorandom, uniformly distributed float value between 0.0 inclusive and 1 exclusive.
    • nextFloat

      public static float nextFloat(float min, float max)
      Returns a pseudorandom, uniformly distributed float value between min (inclusive) and max value (inclusive)
      Parameters:
      min - the inclusive min value
      max - the inclusive max value
      Returns:
      the random float value
    • noise

      public static float noise(float x, float y)
      Generates a Perlin noise value for a 2d time scale.
      Parameters:
      x - the x "time"
      y - the y "time"
      Returns:
      the noise value
    • noise

      public static float noise(float x, float y, int octaves, float falloff)
      Generates a Perlin noise value for a 2d time scale.
      Parameters:
      x - the x "time"
      y - the y "time"
      octaves - smaller values result in larger changes over time
      falloff - how much each higher octave contributes
      Returns:
      the noise value