Use ThreadedLocalRandom for RNG utils

This commit is contained in:
Shane Freeder 2020-01-16 18:21:35 +00:00
parent 421a394f68
commit 406429f4e3
No known key found for this signature in database
GPG Key ID: A3F61EA5A085289C
2 changed files with 4 additions and 5 deletions

View File

@ -1,3 +1,5 @@
Version 2.1.112
Use ThreadedLocalRandom for RNG utils, random is seeded, thus creating new instances of Random breaks randomness
Version 2.1.112 Version 2.1.112
Correct locale usage for enum access, now enforces using the english locale to prevent issues with oddball locales for configs/commands Correct locale usage for enum access, now enforces using the english locale to prevent issues with oddball locales for configs/commands
Fixed a NPE that can occur if a player engages in combat with specific skills before their profile is loaded Fixed a NPE that can occur if a player engages in combat with specific skills before their profile is loaded

View File

@ -13,6 +13,7 @@ import org.bukkit.entity.Player;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
public class RandomChanceUtil public class RandomChanceUtil
{ {
@ -78,9 +79,7 @@ public class RandomChanceUtil
} }
public static boolean rollDice(double chanceOfSuccess, int bound) { public static boolean rollDice(double chanceOfSuccess, int bound) {
Random random = new Random(); return chanceOfSuccess > ThreadLocalRandom.current().nextInt(bound);
return chanceOfSuccess > random.nextInt(bound);
} }
/** /**
@ -100,8 +99,6 @@ public class RandomChanceUtil
{ {
double chanceOfSuccess = calculateChanceOfSuccess(randomChance); double chanceOfSuccess = calculateChanceOfSuccess(randomChance);
Random random = new Random();
//Check the odds //Check the odds
return rollDice(chanceOfSuccess, 100); return rollDice(chanceOfSuccess, 100);
} }