mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
refactor: fixed wrong random value usage
This commit is contained in:
parent
01dd8c33ba
commit
cacf8226aa
4 changed files with 8 additions and 5 deletions
|
|
@ -7,6 +7,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import javax.sound.sampled.*;
|
||||
import mage.client.constants.Constants;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.util.RandomUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -127,7 +128,7 @@ public class MusicPlayer {
|
|||
} catch (Exception e) {
|
||||
}
|
||||
while (!stopped) {
|
||||
int it = (int) Math.abs(Math.random() * (filelist.getItemCount()));
|
||||
int it = (int) Math.abs(RandomUtil.nextDouble() * (filelist.getItemCount()));
|
||||
File file = new File(filepath + filelist.getItem(it));
|
||||
load(file);
|
||||
Thread PlayThread = new Thread(new PlayThread());
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import mage.client.dialog.PreferencesDialog;
|
|||
import mage.components.ImagePanel;
|
||||
import mage.components.ImagePanelStyle;
|
||||
import mage.interfaces.plugin.ThemePlugin;
|
||||
import mage.util.RandomUtil;
|
||||
import net.xeoh.plugins.base.annotations.PluginImplementation;
|
||||
import net.xeoh.plugins.base.annotations.events.PluginLoaded;
|
||||
import net.xeoh.plugins.base.annotations.meta.Author;
|
||||
|
|
@ -111,7 +112,7 @@ public class ThemePluginImpl implements ThemePlugin {
|
|||
private BufferedImage loadbuffer_random() throws IOException {
|
||||
BufferedImage res;
|
||||
if (loadimages()) {
|
||||
int it = (int) Math.abs(Math.random() * (flist.getItemCount()));
|
||||
int it = (int) Math.abs(RandomUtil.nextDouble() * (flist.getItemCount()));
|
||||
String filename = BackgroundDir + flist.getItem(it);
|
||||
res = ImageIO.read(new File(filename));
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ import mage.abilities.common.PassAbility;
|
|||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
import mage.game.combat.Combat;
|
||||
import mage.game.combat.CombatGroup;
|
||||
import mage.game.turn.Step.StepPart;
|
||||
import mage.players.Player;
|
||||
import mage.util.RandomUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -113,7 +113,7 @@ public class MCTSNode {
|
|||
uct = ((node.visits - node.wins) / (node.visits)) + (selectionCoefficient * Math.sqrt(Math.log(visits) / (node.visits)));
|
||||
else
|
||||
// ensure that a random unvisited node is played first
|
||||
uct = 10000 + 1000 * Math.random();
|
||||
uct = 10000 + 1000 * RandomUtil.nextDouble();
|
||||
if (uct > bestValue) {
|
||||
bestChild = node;
|
||||
bestValue = uct;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import mage.game.Game;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetOpponent;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
/**
|
||||
* @author noxx
|
||||
|
|
@ -70,7 +71,7 @@ class TyrantOfDiscordEffect extends OneShotEffect {
|
|||
while (!stop) {
|
||||
int count = game.getBattlefield().countAll(new FilterPermanent(), opponent.getId(), game);
|
||||
if (count > 0) {
|
||||
int random = (int)(Math.random()*count);
|
||||
int random = (int)(RandomUtil.nextDouble() * count);
|
||||
int index = 0;
|
||||
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(opponent.getId())) {
|
||||
if (index == random) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue