title: Math#random ain't so random?
body: <p>I am finding something odd happening with my program. </p>
  
  <p>This program basically is used for component clicking, as it is a concept to test randomness.</p>
  
  <p><img src="https://i.stack.imgur.com/qa9we.png" alt="enter image description here"></p>
  
  <p>As you can see, it is printing correctly, as it should have a tendency to click towards the middle, which is does perfect.</p>
  
  <p>Problem is, it seems biased.</p>
  
  <pre><code>import java.applet.Applet;
  import java.awt.Point;
  import java.io.File;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.ArrayList;
  import java.awt.*;
  
  public class Testing extends Applet {
  
  /**
   * 
   */
  private static final long serialVersionUID = -2441995094105327849L;
  
  public void init() {
      setSize(WIDTH, HEIGHT);
      img = createImage(WIDTH, HEIGHT);
      g = img.getGraphics();
      paint(g);
      setVisible(true);
      g.setColor(new Color(0, 0, 0));
      g.fillRect(0, 0, WIDTH, HEIGHT);
      g.setColor(new Color(55, 55, 55, 55));
      main();
  }
  
  public final static int WIDTH = 400, HEIGHT = 400;
  public static int[] widths = new int[WIDTH], heights = new int[HEIGHT];
  public static ArrayList&lt;String&gt; set = new ArrayList&lt;String&gt;();
  public Image img;
  public Graphics g;
  
  public void paint(Graphics g) {
      g.drawImage(img, 0, 0, null);
  }
  
  public void update(Graphics g) {
      paint(g);
  }
  
  public void main() {
      int count101 = 0;
      int count100 = 0;
      int count99 = 0;
      try {
          PrintWriter pw = new PrintWriter(new FileWriter(
                  new File("Data.dat")));
          Point center = new Point(WIDTH / 2, HEIGHT / 2);
  
          int runs = 10000000;
  
          for (int i = 0; i &lt; runs; i++) {
              int x = center.x
                      - (int) ((Math.random() - Math.random())
                              * Math.random() * center.x);
              int y = center.y
                      - (int) ((Math.random() - Math.random())
                              * Math.random() * center.y);
              widths[x]++;
              heights[y]++;
              repaint();
              g.fillRect(x, y, 1, 1);
              if((x &amp; y) == 101){
                  count101++;
              }
              if((x &amp; y) == 100){
                  count100++;
              }
              if((x &amp; y) == 99){
                  count99++;
              }
          }
          System.out.println(count101);
          System.out.println(count100);
          System.out.println(count99);
          repaint();
          pw.flush();
          pw.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  }
  </code></pre>
  
  <p>This constantly prints biased results.</p>
  
  <p>It prints the following: </p>
  
  <pre><code>3640
  10918
  3741
  </code></pre>
  
  <p>This is considerably biased because it follows a trend for the most part, following a linear increase with all the other values, but once it reaches the 100 mark it decides that it is going to drop the bomb and pick it 6% more then every other.</p>
  
  <p>Anyone know any reasoning for this?</p>
  
  <p>Oh, by the way, I do have a txt file containing every result printed out with repetition of 10,000,000 times with percentages etc, it is quite long so I won't post, but I do have the info.</p>