aboutsummaryrefslogtreecommitdiff
path: root/src/Java
diff options
context:
space:
mode:
authorDavid Vierra <codewarrior@hawaii.rr.com>2018-01-28 03:05:36 -1000
committerDavid Vierra <codewarrior@hawaii.rr.com>2018-01-29 05:02:41 -1000
commit1cdaae2a49cc4c875f33d48cd04d2c97db34bc3a (patch)
tree140eaa51dbcb0842ecb4e29dc3ae43ed5c7cfd16 /src/Java
parenta47674eca1d1411d0d5b006c4e3f97ddf49cb655 (diff)
downloadGT5-Unofficial-1cdaae2a49cc4c875f33d48cd04d2c97db34bc3a.tar.gz
GT5-Unofficial-1cdaae2a49cc4c875f33d48cd04d2c97db34bc3a.tar.bz2
GT5-Unofficial-1cdaae2a49cc4c875f33d48cd04d2c97db34bc3a.zip
Don't create a new RNG instance for each call to MathUtils.randInt etc
Fixes all kinds of performance problems. These RNGs aren't cheap to create.
Diffstat (limited to 'src/Java')
-rw-r--r--src/Java/gtPlusPlus/core/util/math/MathUtils.java14
1 files changed, 2 insertions, 12 deletions
diff --git a/src/Java/gtPlusPlus/core/util/math/MathUtils.java b/src/Java/gtPlusPlus/core/util/math/MathUtils.java
index 679757576f..21c8fa840b 100644
--- a/src/Java/gtPlusPlus/core/util/math/MathUtils.java
+++ b/src/Java/gtPlusPlus/core/util/math/MathUtils.java
@@ -22,11 +22,10 @@ public class MathUtils {
* @return Integer between min and max, inclusive.
* @see java.util.Random#nextInt(int)
*/
- public static int randInt(final int min, final int max) {
- // Usually this can be a field rather than a method variable
- final Random rand = CSPRNG.generate(CORE.RANDOM);
+ final static Random rand = CSPRNG.generate(CORE.RANDOM);
+ public static int randInt(final int min, final int max) {
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
final int randomNum = rand.nextInt((max - min) + 1) + min;
@@ -51,9 +50,6 @@ public class MathUtils {
* @see java.util.Random#nextLong(long)
*/
public static long randLong(final long min, final long max) {
- // Usually this can be a field rather than a method variable
- final Random rand = CSPRNG.generate(CORE.RANDOM);
-
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
final long randomNum = MathUtils.nextLong(rand,(max - min) + 1) + min;
@@ -82,9 +78,6 @@ public class MathUtils {
* @see java.util.Random#nextDouble(double)
*/
public static double randDouble(final double min, final double max) {
- // Usually this can be a field rather than a method variable
- final Random rand = CSPRNG.generate(CORE.RANDOM);
-
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
final double randomNum = MathUtils.nextDouble(rand,(max - min) + 1) + min;
@@ -112,9 +105,6 @@ public class MathUtils {
* @see java.util.Random#nextFloat(float)
*/
public static float randFloat(final float min, final float max) {
- // Usually this can be a field rather than a method variable
- final Random rand = CSPRNG.generate(CORE.RANDOM);
-
// nextInt is normally exclusive of the top value,
// so add 1 to make it inclusive
final float randomNum = MathUtils.nextFloat(rand,(max - min) + 1) + min;