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>
This commit is contained in:
Todor Balabanov
2019-05-01 16:11:30 +02:00
committed by Noel Grandin
parent df512e7475
commit 209e40de80
@@ -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;
}