具体的には、均一な分布については、10 ピクセルごとに 1 つのランダムな位置で問題ないようです。

ちょっと待って、1 ピクセルあたり 1 つのランダムな位置を使用すると、シードされたスレッド化アプローチの方がさらに優れているように見えます!? 完全に均一な分布 (サイズ 250000 の場合) では、すべて黒になります。

左:
public class SingleRandomProof extends JFrame {
public static final int WIDTH = 500;
public static final int HEIGHT = 500;
public static final int SIZE = WIDTH * HEIGHT;
public static void main(String[] args) {
SingleRandomProof proof = new SingleRandomProof();
proof.pack();
proof.setVisible(true);
proof.doCalc();
}
private JLabel panel;
public SingleRandomProof() throws HeadlessException {
super("1 random");
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
panel = new JLabel(new ImageIcon(image));
setContentPane(panel);
}
private void doCalc() {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, WIDTH, HEIGHT);
g.setColor(Color.BLACK);
Random r = new Random(37);
for (int i = 0; i < SIZE; i++) {
int position = r.nextInt(SIZE);
g.fillRect(position % HEIGHT, position / HEIGHT, 1, 1);
}
panel.setIcon(new ImageIcon(image));
}
}
右:
public class SeededThreadRandomProof extends JFrame {
public static final int WIDTH = 500;
public static final int HEIGHT = 500;
public static final int SIZE = WIDTH * HEIGHT;
public static void main(String[] args) {
SeededThreadRandomProof proof = new SeededThreadRandomProof();
proof.pack();
proof.setVisible(true);
proof.doCalc();
}
private JLabel panel;
public SeededThreadRandomProof() throws HeadlessException {
super("10 seeded randoms");
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
panel = new JLabel(new ImageIcon(image));
setContentPane(panel);
}
private void doCalc() {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, WIDTH, HEIGHT);
g.setColor(Color.BLACK);
Random initRandom = new Random(37);
for (int j = 0; j < 10; j++) {
Random r = new Random(initRandom.nextLong());
for (int i = 0; i < SIZE / 10; i++) {
int position = r.nextInt(SIZE);
g.fillRect(position % HEIGHT, position / HEIGHT, 1, 1);
}
}
panel.setIcon(new ImageIcon(image));
}
}