Package com.valhalla.sdk.api.methods
Class Calculations
java.lang.Object
com.valhalla.sdk.api.methods.Calculations
Deterministic-testable timing, distance, and random helpers for scripts.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanchance(int target) Performs a percentage chance roll.static booleanchance(int target, int overall) Performs atarget / overallchance roll.static doubledistance(int x1, int y1, int x2, int y2) Computes Euclidean distance between two coordinates.static doubleComputes Euclidean distance between two tiles, ignoring plane.static longelapsed(long previousTime) Computes elapsed wall-clock time.static StringReturns a 16-character alphanumeric pseudo-random string.static RandomReturns the shared pseudo-random generator used by this utility.static booleanisBefore(long futureTime) Tests a wall-clock deadline.static doublenextGammaRandom(int shape, int scale) Compatibility alias for the distribution helper exposed byRandoms.static doublenextGaussianRandom(double mean, double sigma) Samples a Gaussian distribution.static doublenextHypergeometricRandom(int populationSize, int numberOfSuccesses, int sampleSize) Compatibility alias for the distribution helper exposed byRandoms.static doublenextLogNormalDistributionRandom(double scale, double shape) Compatibility alias for the distribution helper exposed byRandoms.static doublerandom(double minimum, double maximum) Samples a finite double strictly between two 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)without modulo bias.static voidsetRandomSeed(long seed) Sets the deterministic seed for subsequent pseudo-random calls.
-
Method Details
-
getRandom
Returns the shared pseudo-random generator used by this utility.- Returns:
- the shared pseudo-random generator used by this utility
-
setRandomSeed
public static void setRandomSeed(long seed) Sets the deterministic seed for subsequent pseudo-random calls. @param seed new seed -
random
public static int random(int high) Samples an integer from[0, high).- Parameters:
high- exclusive upper bound; must be positive- 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)without modulo bias.- Parameters:
minimum- inclusive lower boundmaximum- exclusive upper bound- Returns:
- a sampled long
-
random
public static double random(double minimum, double maximum) Samples a finite double strictly between two 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 outcomes; must be positive- Returns:
- the result of the roll
-
distance
public static double distance(int x1, int y1, int x2, int y2) Computes Euclidean distance between two coordinates.- Parameters:
x1- first x coordinatey1- first y coordinatex2- second x coordinatey2- second y coordinate- Returns:
- Euclidean distance
-
distance
Computes Euclidean distance between two tiles, ignoring plane.- Parameters:
first- first tilesecond- second tile- Returns:
- Euclidean distance
-
elapsed
public static long elapsed(long previousTime) Computes elapsed wall-clock time.- Parameters:
previousTime- earlier epoch time in milliseconds- Returns:
- non-negative elapsed milliseconds
-
isBefore
public static boolean isBefore(long futureTime) Tests a wall-clock deadline.- Parameters:
futureTime- deadline as epoch milliseconds- Returns:
truebefore the deadline
-
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
-
nextLogNormalDistributionRandom
public static double nextLogNormalDistributionRandom(double scale, double shape) Compatibility alias for the distribution helper exposed byRandoms.- Parameters:
scale- positive distribution scaleshape- positive distribution shape- Returns:
- a sampled log-normal value
-
nextGammaRandom
public static double nextGammaRandom(int shape, int scale) Compatibility alias for the distribution helper exposed byRandoms.- Parameters:
shape- positive integer shapescale- positive integer scale- Returns:
- a sampled gamma value
-
nextHypergeometricRandom
public static double nextHypergeometricRandom(int populationSize, int numberOfSuccesses, int sampleSize) Compatibility alias for the distribution helper exposed byRandoms.- Parameters:
populationSize- positive population sizenumberOfSuccesses- successful members in the populationsampleSize- number of members drawn without replacement- Returns:
- the sampled number of successes
-
generateRandomString
Returns a 16-character alphanumeric pseudo-random string.- Returns:
- a 16-character alphanumeric pseudo-random string
-