title: How to create a random integer array generator
body: <p>I have created a method which takes generate random numbers with the condition that the next random number doesn't match with the previous one inside the array here's the code</p>
  
  <pre><code>// some code   
  
  int k=0;
  
  //some code....
  
  randomgenerator(k); // method call
  
  public void randomgenerator(int j)
  {
  
      for(j=0; j&lt;=99; j++){
          if(j &gt;= 1){
              if (randomset.get(j) == randomset.get(j-1)){
                  randomset.add(0 + ( j  ,  int)(Math.random() * ((99 - 0) + 1)));
              }
              else{
                  randomset.add(0 + (int)(Math.random() * ((99 - 0) + 1)));
              }
          }       
      }
  }
  </code></pre>
  
  <p>The error I get is  <strong>java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1</strong></p>