summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodor Balabanov <todor.balabanov@gmail.com>2019-04-29 18:55:25 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-05-01 16:11:30 +0200
commit209e40de80dec55427d406951f01507a6c8aeb84 (patch)
tree313938753cf8052e9444913a0474ece0659d6f45
parentdf512e74753667194faa623b99884d3590597cfd (diff)
Random class is better than Math random function.
Change-Id: Ia35e3bb3b4f0323c7fbfc54ae5064afdf2c3f381 Reviewed-on: https://gerrit.libreoffice.org/71539 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java11
1 files changed, 8 insertions, 3 deletions
diff --git a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java
index b59b0f8b19ed..d7fafc9b9046 100644
--- a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java
+++ b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java
@@ -22,7 +22,13 @@
package net.adaptivebox.global;
+import java.util.Random;
+
public class RandomGenerator {
+ /**
+ * Pseudo-random number generator instance.
+ */
+ private static Random PRNG = new Random();
/**
* This function returns a random integer number between the lowLimit and
@@ -34,8 +40,7 @@ public class RandomGenerator {
* @return int return value Example: for find [0,1,2]
*/
public static int intRangeRandom(int lowLimit, int upLimit) {
- int num = (int) Math
- .floor(doubleRangeRandom(lowLimit, upLimit + 1) - 1E-10);
+ int num = lowLimit + PRNG.nextInt(upLimit - lowLimit + 1);
return num;
}
@@ -49,7 +54,7 @@ public class RandomGenerator {
* @return double return value
*/
public static double doubleRangeRandom(double lowLimit, double upLimit) {
- double num = lowLimit + Math.random() * (upLimit - lowLimit);
+ double num = lowLimit + PRNG.nextDouble() * (upLimit - lowLimit);
return num;
}