Class RandomService


  • public class RandomService
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      RandomService()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int between​(int min, int max)
      generate random number between min and max
      static boolean diceFractional​(double fractionalChance)
      Simulates a dice roll using a fractional probability (e.g., 0.1 for 10%).
      static boolean dicePercentage​(double percentageChance)
      Simulates a dice roll using a whole number percentage (e.g., 10 for 10%).
      static double gaussRand​(double mean, double dev)
      Generates a random value based on a Gaussian (normal) distribution with a specified mean and standard deviation.
      static int nextInt​(int min, int max, double skewFactor, boolean useGaussian)
      Generates a random integer between min (inclusive) and max (inclusive) with options for skewing the distribution towards either the lower or higher bound.
      static double normalRange​(double min, double max, double cutoff)
      Generates a random number within the specified range, biased towards the mean.
      static long normalRange​(long min, long max, double cutoff)
      Generates a random long value within the specified range, biased towards the mean.
      static double nzRandom()
      Returns a non-zero random double value.
      static int randomGaussian​(double mean, double stddev)
      random gaussian
      static net.runelite.api.Point randomPoint​(java.awt.Rectangle rect, double cutoff)
      Generates a random point within the bounds of the given rectangle, biased towards the center.
      static net.runelite.api.Point randomPoint​(net.runelite.api.Point mean, int maxRad, double cutoff)
      Generates a random point on the screen, weighted around a central point (mean) within a maximum radius.
      static net.runelite.api.Point randomPointEx​(net.runelite.api.Point from, java.awt.Rectangle rect, double force)
      Generates a random point within the bounds of a rectangle, skewed towards a specified 'from' point.
      static double skewedRand​(double mode, double lo, double hi, double cutoff)
      Generates a random number skewed towards the specified mode within a specified range.
      static long skewedRand​(long mode, long lo, long hi, double cutoff)
      Generates a random long value skewed towards the specified mode within a specified range.
      static double truncatedGauss​(double left, double right, double cutoff)
      Generates a random number within the given range using a truncated Gaussian distribution.
      static long truncatedGauss​(long left, long right, double cutoff)
      Generates a random long value within the given range using a truncated Gaussian distribution.
      static void wait​(double min, double max, com.kraken.api.service.util.RandomService.EWaitDir weight)
      Simulates a wait with a random duration, biased towards the mean, left, or right of the given range.
      static void wait​(int min, int max)
      Simulates a wait with a random duration, biased towards the left side of the given range.
      static void waitEx​(double mean, double dev)
      Waits for a random duration based on a Gaussian distribution.
      • Methods inherited from class java.lang.Object

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

      • RandomService

        public RandomService()
    • Method Detail

      • nzRandom

        public static double nzRandom()
        Returns a non-zero random double value. Ensures that the result is always greater than a very small number (1.0e-320), preventing the generation of an exact zero.
        Returns:
        A non-zero random double value.
      • gaussRand

        public static double gaussRand​(double mean,
                                       double dev)
        Generates a random value based on a Gaussian (normal) distribution with a specified mean and standard deviation.
        Parameters:
        mean - The mean (center) value of the distribution.
        dev - The standard deviation of the distribution.
        Returns:
        A random double value from the Gaussian distribution.
      • truncatedGauss

        public static double truncatedGauss​(double left,
                                            double right,
                                            double cutoff)
        Generates a random number within the given range using a truncated Gaussian distribution. This ensures that the value is within the bounds of the left and right range.
        Parameters:
        left - The minimum bound of the range.
        right - The maximum bound of the range.
        cutoff - The cutoff value to restrict extreme values. Defaults to GAUSS_CUTOFF(4) if less than or equal to 0.
        Returns:
        A random double value within the specified range.
      • truncatedGauss

        public static long truncatedGauss​(long left,
                                          long right,
                                          double cutoff)
        Generates a random long value within the given range using a truncated Gaussian distribution.
        Parameters:
        left - The minimum bound of the range.
        right - The maximum bound of the range.
        cutoff - The cutoff value to restrict extreme values.
        Returns:
        A random long value within the specified range.
      • skewedRand

        public static double skewedRand​(double mode,
                                        double lo,
                                        double hi,
                                        double cutoff)
        Generates a random number skewed towards the specified mode within a specified range. This allows for a biased distribution where the values tend to cluster around the mode.
        Parameters:
        mode - The central value around which the distribution is skewed.
        lo - The lower bound of the range.
        hi - The upper bound of the range.
        cutoff - The cutoff value to restrict extreme values. Defaults to GAUSS_CUTOFF(4) if less than or equal to 0.
        Returns:
        A random double value skewed towards the mode.
      • skewedRand

        public static long skewedRand​(long mode,
                                      long lo,
                                      long hi,
                                      double cutoff)
        Generates a random long value skewed towards the specified mode within a specified range.
        Parameters:
        mode - The central value around which the distribution is skewed.
        lo - The lower bound of the range.
        hi - The upper bound of the range.
        cutoff - The cutoff value to restrict extreme values.
        Returns:
        A random long value skewed towards the mode.
      • normalRange

        public static double normalRange​(double min,
                                         double max,
                                         double cutoff)
        Generates a random number within the specified range, biased towards the mean. The distribution has a higher likelihood of generating numbers closer to the midpoint of the range.
        Parameters:
        min - The minimum bound of the range.
        max - The maximum bound of the range.
        cutoff - The cutoff value to restrict extreme values. Defaults to GAUSS_CUTOFF(4) if less than or equal to 0.
        Returns:
        A random double value within the specified range, biased towards the middle.
      • normalRange

        public static long normalRange​(long min,
                                       long max,
                                       double cutoff)
        Generates a random long value within the specified range, biased towards the mean.
        Parameters:
        min - The minimum bound of the range.
        max - The maximum bound of the range.
        cutoff - The cutoff value to restrict extreme values. Defaults to GAUSS_CUTOFF(4) if less than or equal to 0.
        Returns:
        A random long value within the specified range, biased towards the middle.
      • randomPoint

        public static net.runelite.api.Point randomPoint​(net.runelite.api.Point mean,
                                                         int maxRad,
                                                         double cutoff)
        Generates a random point on the screen, weighted around a central point (mean) within a maximum radius. The point is selected to simulate human-like randomness in mouse movement or other actions.
        Parameters:
        mean - The central point to weight the randomness around.
        maxRad - The maximum radius away from the central point.
        cutoff - The cutoff value for restricting extreme values. Defaults to GAUSS_CUTOFF(4) if less than or equal to 0.
        Returns:
        A random point near the central point, within the specified radius.
      • randomPoint

        public static net.runelite.api.Point randomPoint​(java.awt.Rectangle rect,
                                                         double cutoff)
        Generates a random point within the bounds of the given rectangle, biased towards the center. This method is useful for simulating human-like randomness in screen interactions.
        Parameters:
        rect - The rectangular area within which to generate the random point.
        cutoff - The cutoff value for restricting extreme values. Defaults to GAUSS_CUTOFF(4) if less than or equal to 0.
        Returns:
        A random point within the rectangle, biased towards the middle.
      • randomPointEx

        public static net.runelite.api.Point randomPointEx​(net.runelite.api.Point from,
                                                           java.awt.Rectangle rect,
                                                           double force)
        Generates a random point within the bounds of a rectangle, skewed towards a specified 'from' point. Useful for simulating more human-like randomness in actions such as dragging or moving the mouse.
        Parameters:
        from - The point to bias the random point generation towards.
        rect - The rectangular area within which to generate the random point.
        force - A multiplier that defines how strongly the point should be skewed towards the 'from' point.
        Returns:
        A random point within the rectangle, skewed towards the 'from' point.
      • diceFractional

        public static boolean diceFractional​(double fractionalChance)
        Simulates a dice roll using a fractional probability (e.g., 0.1 for 10%).
        Parameters:
        fractionalChance - A decimal between 0 and 1 representing the chance.
        Returns:
        True if the random number falls within the chance, false otherwise.
      • dicePercentage

        public static boolean dicePercentage​(double percentageChance)
        Simulates a dice roll using a whole number percentage (e.g., 10 for 10%).
        Parameters:
        percentageChance - A whole number between 0 and 100 representing the chance.
        Returns:
        True if the random number falls within the chance, false otherwise.
      • wait

        public static void wait​(double min,
                                double max,
                                com.kraken.api.service.util.RandomService.EWaitDir weight)
        Simulates a wait with a random duration, biased towards the mean, left, or right of the given range. This method is useful for introducing randomness in bot actions to reduce predictability.
        Parameters:
        min - The minimum wait time in milliseconds.
        max - The maximum wait time in milliseconds.
        weight - The direction of bias for the wait time (left, mean, or right skew).
      • wait

        public static void wait​(int min,
                                int max)
        Simulates a wait with a random duration, biased towards the left side of the given range.
        Parameters:
        min - The minimum wait time in milliseconds.
        max - The maximum wait time in milliseconds.
      • waitEx

        public static void waitEx​(double mean,
                                  double dev)
        Waits for a random duration based on a Gaussian distribution. The wait time is calculated using a normal distribution with the specified mean and standard deviation.
        Parameters:
        mean - The mean wait time in milliseconds.
        dev - The standard deviation of the wait time.
      • nextInt

        public static int nextInt​(int min,
                                  int max,
                                  double skewFactor,
                                  boolean useGaussian)
        Generates a random integer between min (inclusive) and max (inclusive) with options for skewing the distribution towards either the lower or higher bound.
        Parameters:
        min - The minimum value (inclusive).
        max - The maximum value (inclusive).
        skewFactor - The skew factor. A value greater than 1 will skew the distribution towards the higher end, while a value less than 1 will skew it towards the lower end. A value of 1 produces a standard Gaussian distribution centered around the midpoint.
        useGaussian - If true, the method will use a Gaussian distribution instead of a uniform one.
        Returns:
        A random integer between min and max, possibly skewed based on the parameters.
      • between

        public static int between​(int min,
                                  int max)
        generate random number between min and max
        Parameters:
        min - The minimum the random number can be
        max - The maximum the random number can be
        Returns:
        A random number between the minimum and maximum
      • randomGaussian

        public static int randomGaussian​(double mean,
                                         double stddev)
        random gaussian
        Parameters:
        mean - The mean
        stddev - The standard deviation
        Returns:
        a random gaussian distribution