title: Why am I receiving "bound must be positive" error?
body: <p>I am trying to write code that simulates a game of Scrabble.  I designed a class which should simulate a Scrabble bag, and I am trying to test it by printing the <code>tileID</code> in <code>main()</code> after choosing a random tile.  Whenever I run the code though, I keep getting the following error:</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.IllegalArgumentException: bound must be positive
      at java.util.Random.nextInt(Random.java:388)
      at hw3.RandomBag.randomPick(RandomBag.java:39)
      at hw3.RandomBag.main(RandomBag.java:59`
  </code></pre>
  <p>Can somebody tell me why I am receiving that error?</p>
  <pre><code>import java.util.*;
  
  public class RandomBag&lt;E&gt; implements Iterable&lt;E&gt; {
      
      // instance varibles
      private List&lt;E&gt; bag; // arraylist as the container
      private Random rand; // random number generator
      
      // constructors
      public RandomBag() { 
          bag = new ArrayList&lt;E&gt;();
          rand = new Random();    
      }
      
      public RandomBag(int seed) { 
          bag = new ArrayList&lt;E&gt;();
          rand = new Random(seed);
          
      }
      
      // returns the size of the bag
      public int size() { return this.bag.size(); }  
      
      public boolean isEmpty() { // returns true/false if the bag is/is not empty
          if (this.bag.isEmpty())
              return true;
          else
              return false;
      }  
      
      // adds the parameter element in the bag
      public void add (E element) {this.bag.add(element);} 
      
      // randomly selects an element using the random number generator 'rand' and removes that element from the bag, and returns the element
      public E randomPick() {
          
          int index = rand.nextInt(this.bag.size());
          E tileID = bag.remove(index);
          return tileID;
      } 
      
      // obtains an iterator for the bag, and returns it
      public Iterator&lt;E&gt; iterator() {
          // traverse bag using an iterator
          Iterator it = bag.iterator();
          return it;
      }
      
        //**
        //** main() for testing RandomBag&lt;E&gt;
        //**
      public static void main(String[] args) {
          
          RandomBag bag = new RandomBag();   
          
          Object tileID = bag.randomPick(); 
          System.out.println(tileID);
  
      }
  }
  </code></pre>