summaryrefslogtreecommitdiff
path: root/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java
diff options
context:
space:
mode:
Diffstat (limited to 'nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java')
-rw-r--r--nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java99
1 files changed, 48 insertions, 51 deletions
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java
index 18ced86335dc..4910de990091 100644
--- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java
@@ -25,63 +25,60 @@ package net.adaptivebox.global;
import java.util.Random;
public class RandomGenerator {
- /**
- * Pseudo-random number generator instance.
- */
- private static Random PRNG = new Random();
+ /**
+ * Pseudo-random number generator instance.
+ */
+ private static Random PRNG = new Random();
- /**
- * This function returns a random integer number between the lowLimit and
- * upLimit.
- *
- * @param lowLimit
- * lower limits upLimit The upper limits (between which the
- * random number is to be generated)
- * @return int return value Example: for find [0,1,2]
- */
- public static int intRangeRandom(int lowLimit, int upLimit) {
- int num = lowLimit + PRNG.nextInt(upLimit - lowLimit + 1);
- return num;
- }
-
- /**
- * This function returns a random float number between the lowLimit and
- * upLimit.
- *
- * @param lowLimit
- * lower limits upLimit The upper limits (between which the
- * random number is to be generated)
- * @return double return value
- */
- public static double doubleRangeRandom(double lowLimit, double upLimit) {
- double num = lowLimit + PRNG.nextDouble() * (upLimit - lowLimit);
- return num;
- }
+ /**
+ * This function returns a random integer number between the lowLimit and
+ * upLimit.
+ *
+ * @param lowLimit lower limits upLimit The upper limits (between which the
+ * random number is to be generated)
+ * @return int return value Example: for find [0,1,2]
+ */
+ public static int intRangeRandom(int lowLimit, int upLimit) {
+ int num = lowLimit + PRNG.nextInt(upLimit - lowLimit + 1);
+ return num;
+ }
- public static int[] randomSelection(int maxNum, int times) {
- if (maxNum < 0) {
- maxNum = 0;
- }
+ /**
+ * This function returns a random float number between the lowLimit and upLimit.
+ *
+ * @param lowLimit lower limits upLimit The upper limits (between which the
+ * random number is to be generated)
+ * @return double return value
+ */
+ public static double doubleRangeRandom(double lowLimit, double upLimit) {
+ double num = lowLimit + PRNG.nextDouble() * (upLimit - lowLimit);
+ return num;
+ }
- if (times < 0) {
- times = 0;
- }
+ public static int[] randomSelection(int maxNum, int times) {
+ if (maxNum < 0) {
+ maxNum = 0;
+ }
- int[] all = new int[maxNum];
- for (int i = 0; i < all.length; i++) {
- all[i] = i;
- }
+ if (times < 0) {
+ times = 0;
+ }
- /* https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle */
- int[] indices = new int[Math.min(maxNum, times)];
- for (int i = 0, j, value; i < indices.length; i++) {
- j = intRangeRandom(i, all.length - 1);
+ int[] all = new int[maxNum];
+ for (int i = 0; i < all.length; i++) {
+ all[i] = i;
+ }
- value = all[j];
- all[j] = all[i];
- indices[i] = all[i] = value;
- }
+ /* https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle */
+ int[] indices = new int[Math.min(maxNum, times)];
+ for (int i = 0, j, value; i < indices.length; i++) {
+ j = intRangeRandom(i, all.length - 1);
- return indices;
+ value = all[j];
+ all[j] = all[i];
+ indices[i] = all[i] = value;
}
+
+ return indices;
+ }
}