Package com.valhalla.sdk.api.methods
Class Randoms
java.lang.Object
com.valhalla.sdk.api.methods.Randoms
Random helpers compatible with the common DreamBot scripting surface.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanchance(int target) Performs a percentage chance roll.static booleanchance(int target, int overall) Performs atarget / overallchance roll.static RandomReturns the process-wide cryptographically strong random generator.static doublegetSeededDouble(String seed, double minimum, double maximum) Deterministically samples a double for a text seed.static intgetSeededInt(String seed, int minimum, int maximum) Deterministically samples an integer for a text seed.static doublenextGammaRandom(int shape, int scale) Marsaglia-Tsang gamma sampler, including shape values below one.static doublenextGaussianRandom(double mean, double sigma) Samples a Gaussian distribution.static doublenextHypergeometricRandom(int populationSize, int numberOfSuccesses, int sampleSize) Samples the number of successes drawn without replacement.static doublenextLogNormalDistributionRandom(double scale, double shape) Samples a log-normal distribution using the secure generator.static doublerandom(double minimum, double maximum) Samples a double strictly between two finite bounds.static intrandom(int high) Samples an integer from[0, high).static intrandom(int minimum, int maximum) Samples an integer from[minimum, maximum).static longrandom(long minimum, long maximum) Samples a long from[minimum, maximum).static voidsetSeed(long seed) Sets the pseudo-random compatibility seed.static voidSets a seed derived from text.
-
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 boundmaximum- 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 boundmaximum- 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 boundmaximum- 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 atarget / overallchance roll.- Parameters:
target- successful outcomesoverall- 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 meansigma- non-negative standard deviation- Returns:
- a sampled value
-
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
Sets a seed derived from text. @param salt text to hash deterministically -
getSeededInt
Deterministically samples an integer for a text seed.- Parameters:
seed- stable seed textminimum- inclusive lower boundmaximum- exclusive upper bound- Returns:
- the sampled integer
-
getSeededDouble
Deterministically samples a double for a text seed.- Parameters:
seed- stable seed textminimum- inclusive lower boundmaximum- 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 scaleshape- 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 shapescale- 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 sizenumberOfSuccesses- successful members in the populationsampleSize- members drawn without replacement- Returns:
- the sampled number of successes
-