Package org.dreambot.api.methods
Class Calculations
- java.lang.Object
-
- org.dreambot.api.methods.Calculations
-
public final class Calculations extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Calculations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
chance(int target)
Checks if the given {@param target} is less than or equal to a random value between 0(inclusive) and 100 (exclusive)static boolean
chance(int target, int overall)
Checks if the given {@param target} is less than or equal to a random value between 0(inclusive) and {@param overall}(exclusive) Method just returns Calculations.random(overall) <= targetstatic double
distance(int x1, int y1, int x2, int y2)
Calculates the distance between two sets of coordinatesstatic double
distance(java.awt.Point p1, java.awt.Point p2)
Calculates the distance between two pointsstatic double
distance(Tile t1, Tile t2)
Calculates the distance between two tiles.static long
elapsed(long prevTime)
Calculates the time elapsed from the supplied previous time.static java.lang.String
generateRandomString()
static java.util.Random
getRandom()
static boolean
isBefore(long futureTime)
Returns true if System time is less than inputstatic double
nextGammaRandom(int shape, int scale)
Generates a random value from theGammaDistribution
static double
nextGaussianRandom(double mean, double sigma)
Generates a random value from the Normal (or Gaussian) distribution with specified mean and standard deviation.static double
nextHypergeometricRandom(int populationSize, int numberOfSuccesses, int sampleSize)
Generates a random value from theHypergeometricDistribution
.static double
nextLogNormalDistributionRandom(double scale, double shape)
Generates a lognormal distribution using the provided parameters with an inverse absolute accuracy of 1e-9 and uses a Well19937c number generator to return a samplestatic double
random(double lower, double upper)
Generates a uniformly distributed random value from the open interval (lower, upper) (i.e., endpoints excluded).static int
random(int high)
Returns a number between 0 (inclusive) and high (exclusive)static int
random(int min, int max)
Gets a random number between min (inclusive) and max (exclusive)static long
random(long min, long max)
Gets a random number between min (inclusive) and max (exclusive)static void
setRandomSeed(long seed)
-
-
-
Method Detail
-
random
public static int random(int high)
Returns a number between 0 (inclusive) and high (exclusive)- Parameters:
high
- upper bounds of random number (exclusive)- Returns:
- int between 0(inclusive) and max(exclusive)
-
random
public static int random(int min, int max)
Gets a random number between min (inclusive) and max (exclusive)- Parameters:
min
- minimum numbermax
- maximum number- Returns:
- int between min(inclusive) and max(exclusive)
-
nextLogNormalDistributionRandom
public static double nextLogNormalDistributionRandom(double scale, double shape) throws org.apache.commons.math3.exception.NotStrictlyPositiveException
Generates a lognormal distribution using the provided parameters with an inverse absolute accuracy of 1e-9 and uses a Well19937c number generator to return a sample- Parameters:
scale
- scale parameter (median of the distribution)shape
- shape parameter (std. dev. of the log of the distribution)- Returns:
- a sample from the distribution
- Throws:
org.apache.commons.math3.exception.NotStrictlyPositiveException
- if shape is less than or equal to 0
-
random
public static double random(double lower, double upper)
Generates a uniformly distributed random value from the open interval (lower, upper) (i.e., endpoints excluded).- Parameters:
lower
- the exclusive lower bound of the supportupper
- the exclusive upper bound of the support- Returns:
- a uniformly distributed random value between lower and upper (exclusive)
- Throws:
org.apache.commons.math3.exception.NumberIsTooLargeException
- if lower is greater than upper.org.apache.commons.math3.exception.NotFiniteNumberException
- if one of the bounds is infiniteorg.apache.commons.math3.exception.NotANumberException
- if one of the bounds is NaN
-
random
public static long random(long min, long max)
Gets a random number between min (inclusive) and max (exclusive)- Parameters:
min
- minimum numbermax
- maximum number- Returns:
- Long between min(inclusive) and max(exclusive)
-
nextGaussianRandom
public static double nextGaussianRandom(double mean, double sigma)
Generates a random value from the Normal (or Gaussian) distribution with specified mean and standard deviation.- Parameters:
mean
- the standard mean of the distributionsigma
- the standard deviation of the distribution- Returns:
- a random value following the specified Gaussian distribution.
- Throws:
org.apache.commons.math3.exception.NotStrictlyPositiveException
- if sigma less or equal to 0.
-
nextHypergeometricRandom
public static double nextHypergeometricRandom(int populationSize, int numberOfSuccesses, int sampleSize)
Generates a random value from theHypergeometricDistribution
.- Parameters:
populationSize
- the population size of the Hypergeometric distribution.numberOfSuccesses
- number of successes in the population of the Hypergeometric distribution.sampleSize
- the sample size of the Hypergeometric distribution.- Returns:
- random value sampled from the Hypergeometric(populationSize, numberOfSuccesses, sampleSize) distribution.
- Throws:
org.apache.commons.math3.exception.NotStrictlyPositiveException
- if shape less or equal to 0 or scale less or equal to 0.
-
nextGammaRandom
public static double nextGammaRandom(int shape, int scale)
Generates a random value from theGammaDistribution
- Parameters:
shape
- the median of the Gamma distributionscale
- the scale parameter of the Gamma distribution- Returns:
- random value sampled from the Gamma(shape, scale) distribution.
- Throws:
org.apache.commons.math3.exception.NotStrictlyPositiveException
- if shape less or equal to 0 or scale less or equal to 0.
-
setRandomSeed
public static void setRandomSeed(long seed)
-
distance
public static double distance(Tile t1, Tile t2)
Calculates the distance between two tiles.- Parameters:
t1
- tile getForceLEShortAt2
- tile B- Returns:
- distance between getForceLEShortA B
-
distance
public static double distance(java.awt.Point p1, java.awt.Point p2)
Calculates the distance between two points- Parameters:
p1
- Point getForceLEShortAp2
- Point B- Returns:
- distance between A and B
-
distance
public static double distance(int x1, int y1, int x2, int y2)
Calculates the distance between two sets of coordinates- Parameters:
x1
- X-coordinate Ay1
- Y-coordinate Ax2
- X-coordinate By2
- Y-coordinate B- Returns:
- distance between A and B
-
getRandom
public static java.util.Random getRandom()
-
isBefore
public static boolean isBefore(long futureTime)
Returns true if System time is less than input- Parameters:
futureTime
- The future time in milliseconds.- Returns:
- true if true
-
elapsed
public static long elapsed(long prevTime)
Calculates the time elapsed from the supplied previous time.- Parameters:
prevTime
-- Returns:
- The Elapsed time
-
generateRandomString
public static java.lang.String generateRandomString()
-
chance
public static boolean chance(int target, int overall)
Checks if the given {@param target} is less than or equal to a random value between 0(inclusive) and {@param overall}(exclusive) Method just returns Calculations.random(overall) <= target- Parameters:
target
- target value to checkoverall
- overall value for a 0 to overall random check- Returns:
- true if {@param target} is less than or equal to
random(int)
with {@param overall} passed to random
-
chance
public static boolean chance(int target)
Checks if the given {@param target} is less than or equal to a random value between 0(inclusive) and 100 (exclusive)- Parameters:
target
- target value to check for- Returns:
- true if {@param target} is less than or equal to a random value between 0(inclusive) and 100 (exclusive)
-
-