title: I keep getting the error "Index 5 out of bounds for length 5" but don't know what to change
body: <p>I'm pretty new to coding so please bear with me, I am just experimenting with ways to shuffle an array for eventual use in shuffling a deck of cards in a card game I am creating in Java. I know that index 5 is out of bounds for length 5 but what is puzzling to me is that the error doesn't ALWAYS pop up. Sometimes I try to run my code and it works just fine, other times I get the error even if I haven't changed anything between times that I run it.</p>
  
  <pre><code>public class Card{
  
      public static void shuffle(Object[] array) {
  
          int noOfCards = array.length;
  
          for (int i = 0; i &lt; noOfCards; i++) {
  
              int s = i + (int)(Math.random() * (noOfCards - 1));
  
              Object temp = array[s]; //this is the first line it says has a problem
              array[s] = array[i];
              array[i] = temp;
          }
      }
  
      public static void main(String[] args) {
  
          String[] strOfCards = {"A","B","C","D","E"};
  
          Card.shuffle(strOfCards); //this is the second line that has a problem
          for(int i = 0; i &lt; strOfCards.length; i++) {
              System.out.println(strOfCards[i] + " ");
          }
      }
  }
  </code></pre>
  
  <p>I have no idea how to change the flawed lines, any suggestions are welcome!
  *** i have tried changing the number of letters in the string but then the error changes with it i.e. "Index 6 out of bounds for length 6"</p>