diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-13 16:54:12 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-04-13 16:54:12 -0400 |
| commit | ba07771f8333f1b098ab8a9ec9fec886b72b9cc0 (patch) | |
| tree | 7d1326235d021cb4767065cddd25bbe9fbdf5ce1 /BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java | |
| parent | 12637af8d6b7b9b2d96deb89e5a09e05178a8e65 (diff) | |
Removed old data types
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java')
| -rw-r--r-- | BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java new file mode 100644 index 0000000..1f8f61d --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NumberUtils.java @@ -0,0 +1,53 @@ +package bjc.utils.funcutils; + +import java.util.function.Function; + +/** + * Utility functions for dealing with numbers + * + * @author ben + * + */ +public class NumberUtils { + /** + * Compute the falling factorial of a number + * + * @param value + * The number to compute + * @param power + * The power to do the falling factorial for + * @return The falling factorial of the number to the power + */ + public static int fallingFactorial(int value, int power) { + if (power == 0) { + return 1; + } else if (power == 1) { + return value; + } else { + int result = 1; + + for (int currentSub = 0; currentSub < power + + 1; currentSub++) { + result *= value - currentSub; + } + + return result; + } + } + + /** + * Evaluates a linear probability distribution + * + * @param topExp + * The number of winning possibilities + * @param bottomExp + * The number of total possibilities + * @param rng + * The function to use to generate a random possibility + * @return Whether or not a random possibility was a winning one + */ + public static boolean isProbable(int topExp, int bottomExp, + Function<Integer, Integer> rng) { + return rng.apply(bottomExp) < topExp; + } +} |
