title: Random Color Change Each Iteration
body: <p>While using an ArrayList, I can't seem to figure out how to reset and re-apply the random color for each iteration of the for loop. I am trying to reset and apply my random color every time my XLeft position is changed. This is only a section of one class I am using, and my getMax() was defined by a Scanner input.  Any suggestions?</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.Random;
  import java.awt.Color;
  import java.awt.Graphics2D;
  import java.awt.Rectangle;
  
  public class BarChart {
  
  private int width, height;
  private ArrayList&lt;Double&gt; values = new ArrayList&lt;Double&gt;();
  private Random generator = new Random();
  int red = generator.nextInt(255);
  int green = generator.nextInt(255);
  int blue = generator.nextInt(255);
  private Color randomColor = new Color(red, green, blue);
  
  
  public BarChart(int aWidth, int aHeight) {
  
      width = aWidth;
      height = aHeight;
  
  }
  
  public void add(double inputValues) {
      values.add(inputValues);
  }
  
  public double getMax() {
  
      double max = values.get(0);
  
      for (int i = 1; i &lt; values.size(); i++) {
          if ((values.get(i)) &gt; max)
              max = values.get(i);
  
      }
      return max;
  }
  
  public void draw(Graphics2D g2) {
  
      int xLeft = 0;
      double barWidth = width / values.size();
  
      for (int i = 0; i &lt; values.size(); i++) {
  
          double barHeight = (values.get(i) / getMax()) * height;
          Rectangle bar = new Rectangle(xLeft, height - ((int) barHeight),
                  (int) barWidth, (int) barHeight);
          g2.setColor(randomColor);
          g2.fill(bar);
          xLeft = (int) (xLeft + barWidth);
          xLeft++;
  
      }
  }
  </code></pre>
  
  <p>}</p>