[Libreoffice-commits] core.git: nlpsolver/ThirdParty

Todor Balabanov (via logerrit) logerrit at kemper.freedesktop.org
Wed May 1 14:12:08 UTC 2019


 nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/global/RandomGenerator.java |   11 +++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

New commits:
commit 209e40de80dec55427d406951f01507a6c8aeb84
Author:     Todor Balabanov <todor.balabanov at gmail.com>
AuthorDate: Mon Apr 29 18:55:25 2019 +0300
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed May 1 16:11:30 2019 +0200

    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 at collabora.co.uk>

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;
     }
 


More information about the Libreoffice-commits mailing list