refactor: fixed wrong random value usage

This commit is contained in:
Oleg Agafonov 2023-11-28 21:48:25 +04:00
parent 01dd8c33ba
commit cacf8226aa
4 changed files with 8 additions and 5 deletions

View file

@ -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());

View file

@ -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;