title: creating a shuffle method for playlist in java
body: <p>Although the instructions below seem to be clear, I am utterly confused on how to implement this code.</p>
  
  <p>One of the most popular features of contemporary music software is the ability to randomize the order of the songs in a playlist—an action called “shuffling” the songs. Create a shuffle method using the below pseudo code as a guide: </p>
  
  <pre><code>create a new empty arraylist (called newList)
  
  while (there are still songs left)
  
  randomly select the index of one song on the playlist
  
  remove it from the current playlist and place it at the end of newList
  
  songs = newList
  </code></pre>
  
  <p>Hint: Generate a random number using the Random class in the Java library. Its method is: 
  public int nextInt(int n).
  This returns a pseudorandom, uniformly distributed int value as low as 0 and as high as n. Therefore, nextInt(songs.size()) gives you a random index. Remember that the size of songs lessens by one each time you add a randomly selected song to newList. You will need to account for this each time you generate a random number.</p>
  
  <p>This is what I have which causes the program to crash. I need help with retrieving a song from the array, removing it, and placing it in a new array list. PLEASE HELP ME!</p>
  
  <pre><code>public int nextInt(int n) {
  
  int index = randomGenerator.nextInt(songs.size());
                return index;
   }
  public void shuffle (){
      newList = new ArrayList&lt;Mp3&gt; ();
      while (songs.size()&gt;0){
          Mp3 song = songs.get(nextInt(songs.size()));
          newList.add(song);
          System.out.println("new list" + newList);
     }
   }
  </code></pre>