title: Specify max and min for Random.nextInt()?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/363681/java-generating-random-number-in-a-range">Java: generating random number in a range</a>  </p>
  </blockquote>
  
  
  
  <p>I want to generate a random int in a logical range. So, say for example, I'm writing a program to "roll" a dice with a specified number of sides.</p>
  
  <pre>public int rollDice() {
       Random generator = new Random();
       return generator.nextInt(sides);
  }</pre>
  
  <p>Now the problem becomes that this will return values between sides and zero, <em>inclusive</em>, which makes no sense because most dice go from 1 to 6, 9, etc. So how can I specify that nextInt should work between 1 and the number of sides?</p>