title: Random is shared between all instances of an object
body: <p>I want to create a bunch of dots and move each of them in a random direction. Problem is that all dots are heading the same direction, so they look like a single dot even if there are a hundred of them. I  tried to google it but found nothing. I bet it's just my stupidity, but I really don't know what to do with it.
  Thanks for helping me.</p>
  <p>Dot class:</p>
  <pre><code>public class Dot extends JPanel {
      
      private PVector pos;
      private PVector vel;
      private PVector acc;
      
      private Brain brain;
      
      private boolean dead = false;
      
      public Dot(){
          this.brain = new Brain(400);
          
          this.pos = new PVector(Main.width/2, Main.height/2);
          this.vel = new PVector(0, 0);
          this.acc = new PVector(0, 0);
      }
  
      @Override
      public void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.fillOval((int)pos.x, (int)pos.y, 4, 4);
      }
      
      public void show(JFrame frame) {
          frame.add(this);
      }
      
      public void move() {
          if(brain.directions.length &gt; brain.step) {
              acc = brain.directions[brain.step];
              brain.step++;
          } else {
              dead = true;
          }
          
          vel.add(acc);
          vel.limit(5);
          pos.add(vel);
      }
      
      public void update() {
          if(!dead) {
              move();
              
              if(pos.y &lt; 2 || pos.y &lt; 2 || pos.x &gt; Main.width - 2 || pos.y &gt; Main.height - 2) {
                  dead = true;
              }
          }
      }
  }
  </code></pre>
  <p>Brain class:</p>
  <pre><code>public class Brain {
  
      public PVector[] directions;
      public int step = 0;
      
      public Brain(int size) {
          directions = new PVector[size];
          randomize();
      }
      
      private void randomize() {
          for(int i = 0; i &lt; directions.length; i++) {
              Random random = new Random();
              float randomAngle = (float)(random.nextFloat() * 2 * Math.PI);
              directions[i] = PVector.fromAngle(randomAngle);
          }
      }
  }
  </code></pre>
  <p>Population class:</p>
  <pre><code>public class Population {
  
      public Dot[] dots;
      
      public Population(int size) {
          dots = new Dot[size];
          
          for(int i = 0; i &lt; size; i++) {
              dots[i] = new Dot();
          }
      }
      
      public void show(JFrame frame) {
          for(int i = 0; i &lt; dots.length; i++) {
              dots[i].show(frame);
          }
      }
      
      public void update() {
          for(int i = 0; i &lt; dots.length; i++) {
              dots[i].update();
          }
      }
  }
  </code></pre>
  <p>Gui class:</p>
  <pre><code>public class Gui {
  
      JFrame frame = new JFrame();
      
      Population test = new Population(100);
      
      public Gui() {
          startup();
      }
      
      private void startup() {
          frame.setSize(Main.width, Main.height);
          frame.setLocation(200, 200);
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setResizable(false);
          
          ScheduledExecutorService executor = Executors
                  .newSingleThreadScheduledExecutor();
          executor.scheduleAtFixedRate(new Runnable() {
              @Override
              public void run() {
                  update();
              }
          }, 0, 1000 / 60, TimeUnit.MILLISECONDS);
          
          test.show(frame);
      }
      
      private void update() {
          frame.repaint();
          
          test.update();
      }
  }
  </code></pre>