Class Randoms

java.lang.Object
com.valhalla.sdk.api.methods.Randoms

public final class Randoms extends Object
Random helpers compatible with the common DreamBot scripting surface.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    chance(int target)
    Performs a percentage chance roll.
    static boolean
    chance(int target, int overall)
    Performs a target / overall chance roll.
    static Random
    Returns the process-wide cryptographically strong random generator.
    static double
    getSeededDouble(String seed, double minimum, double maximum)
    Deterministically samples a double for a text seed.
    static int
    getSeededInt(String seed, int minimum, int maximum)
    Deterministically samples an integer for a text seed.
    static double
    nextGammaRandom(int shape, int scale)
    Marsaglia-Tsang gamma sampler, including shape values below one.
    static double
    nextGaussianRandom(double mean, double sigma)
    Samples a Gaussian distribution.
    static double
    nextHypergeometricRandom(int populationSize, int numberOfSuccesses, int sampleSize)
    Samples the number of successes drawn without replacement.
    static double
    nextLogNormalDistributionRandom(double scale, double shape)
    Samples a log-normal distribution using the secure generator.
    static double
    random(double minimum, double maximum)
    Samples a double strictly between two finite bounds.
    static int
    random(int high)
    Samples an integer from [0, high).
    static int
    random(int minimum, int maximum)
    Samples an integer from [minimum, maximum).
    static long
    random(long minimum, long maximum)
    Samples a long from [minimum, maximum).
    static void
    setSeed(long seed)
    Sets the pseudo-random compatibility seed.
    static void
    Sets a seed derived from text.

    Methods inherited from class java.lang.Object

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

    • random

      public static int random(int high)
      Samples an integer from [0, high).
      Parameters:
      high - exclusive positive upper bound
      Returns:
      a sampled integer
    • random

      public static int random(int minimum, int maximum)
      Samples an integer from [minimum, maximum).
      Parameters:
      minimum - inclusive lower bound
      maximum - exclusive upper bound
      Returns:
      a sampled integer
    • random

      public static long random(long minimum, long maximum)
      Samples a long from [minimum, maximum).
      Parameters:
      minimum - inclusive lower bound
      maximum - exclusive upper bound
      Returns:
      a sampled long
    • random

      public static double random(double minimum, double maximum)
      Samples a double strictly between two finite bounds.
      Parameters:
      minimum - exclusive lower bound
      maximum - exclusive upper bound
      Returns:
      a sampled double
    • chance

      public static boolean chance(int target)
      Performs a percentage chance roll.
      Parameters:
      target - successful percentage points out of 100
      Returns:
      the result of the roll
    • chance

      public static boolean chance(int target, int overall)
      Performs a target / overall chance roll.
      Parameters:
      target - successful outcomes
      overall - total positive outcomes
      Returns:
      the result of the roll
    • nextGaussianRandom

      public static double nextGaussianRandom(double mean, double sigma)
      Samples a Gaussian distribution.
      Parameters:
      mean - distribution mean
      sigma - non-negative standard deviation
      Returns:
      a sampled value
    • getSecureRandom

      public static Random getSecureRandom()
      Returns the process-wide cryptographically strong random generator.
      Returns:
      the process-wide cryptographically strong random generator
    • setSeed

      public static void setSeed(long seed)
      Sets the pseudo-random compatibility seed. @param seed deterministic seed
    • setSeed

      public static void setSeed(String salt)
      Sets a seed derived from text. @param salt text to hash deterministically
    • getSeededInt

      public static int getSeededInt(String seed, int minimum, int maximum)
      Deterministically samples an integer for a text seed.
      Parameters:
      seed - stable seed text
      minimum - inclusive lower bound
      maximum - exclusive upper bound
      Returns:
      the sampled integer
    • getSeededDouble

      public static double getSeededDouble(String seed, double minimum, double maximum)
      Deterministically samples a double for a text seed.
      Parameters:
      seed - stable seed text
      minimum - inclusive lower bound
      maximum - exclusive upper bound
      Returns:
      the sampled double
    • nextLogNormalDistributionRandom

      public static double nextLogNormalDistributionRandom(double scale, double shape)
      Samples a log-normal distribution using the secure generator.
      Parameters:
      scale - positive distribution scale
      shape - positive distribution shape
      Returns:
      a sampled log-normal value
    • nextGammaRandom

      public static double nextGammaRandom(int shape, int scale)
      Marsaglia-Tsang gamma sampler, including shape values below one.
      Parameters:
      shape - positive integer shape
      scale - positive integer scale
      Returns:
      a sampled gamma value
    • nextHypergeometricRandom

      public static double nextHypergeometricRandom(int populationSize, int numberOfSuccesses, int sampleSize)
      Samples the number of successes drawn without replacement.
      Parameters:
      populationSize - positive population size
      numberOfSuccesses - successful members in the population
      sampleSize - members drawn without replacement
      Returns:
      the sampled number of successes