title: Basic Random Rolling Dice Java
body: <p>I am trying to write a method rollDice(int number, int nSides) which returns the total result of rolling the number dice with nSides sides.</p>
  
  <p>So for example rollDice(3, 6) should return the result of rolling 3 six-sided dice (adding to a number between 3 and 18 inclusive).</p>
  
  <p>Below method returns negative numbers when I type 1 for <code>int number</code> what do I need to do to fix this? </p>
  
  <pre><code>public static  int rollDice(int number, int nSides) {
      int num = 0;
        if(nSides &gt;=3)
      {
        for(int i = 0; i &lt; number; i++){
         Random  r = new Random(); 
         int roll = r.nextInt();
         num = num + (roll % nSides)+1;
  
        }
      }
        else{
            System.out.println("Error num needs to be from 3");
  
      }
      return num; 
  } 
  </code></pre>