aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus
diff options
context:
space:
mode:
authorAlkalus <draknyte1@hotmail.com>2018-01-30 01:10:40 +1000
committerGitHub <noreply@github.com>2018-01-30 01:10:40 +1000
commit1b4db193e30b0d0aa04636ff54a23d63f5950e04 (patch)
tree140eaa51dbcb0842ecb4e29dc3ae43ed5c7cfd16 /src/Java/gtPlusPlus
parenta47674eca1d1411d0d5b006c4e3f97ddf49cb655 (diff)
parent1cdaae2a49cc4c875f33d48cd04d2c97db34bc3a (diff)
downloadGT5-Unofficial-1b4db193e30b0d0aa04636ff54a23d63f5950e04.tar.gz
GT5-Unofficial-1b4db193e30b0d0aa04636ff54a23d63f5950e04.tar.bz2
GT5-Unofficial-1b4db193e30b0d0aa04636ff54a23d63f5950e04.zip
Merge pull request #200 from codewarrior0/no-extra-rngs
Don't create a new RNG instance for each call to MathUtils.randInt etc
Diffstat (limited to 'src/Java/gtPlusPlus')
-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;