title: How do I generate a random integer between min and max in Java?
body: <p>What method returns a random int between a min and max? Or does no such method exist?</p>
  
  <p>What I'm looking for is something like this: </p>
  
  <pre><code>NAMEOFMETHOD (min, max) 
  </code></pre>
  
  <p>(where min and max are <code>int</code>s), that returns something like this: </p>
  
  <pre><code>8
  </code></pre>
  
  <p>(randomly) </p>
  
  <p>If such a method does exist could you please link to the relevant documentation with your answer.</p>
  
  <p>Thanks. </p>
  
  <hr>
  
  <h2>UPDATE</h2>
  
  <p>Attempting to implement the full solution and I get the following error message: </p>
  
  <pre><code>class TestR
  {
      public static void main (String[]arg) 
      {   
          Random random = new Random() ;
          int randomNumber = random.nextInt(5) + 2;
          System.out.println (randomNumber) ; 
      } 
  } 
  </code></pre>
  
  <p>I'm still getting the same errors from the compiler: </p>
  
  <pre><code>TestR.java:5: cannot find symbol
  symbol  : class Random
  location: class TestR
          Random random = new Random() ;
          ^
  TestR.java:5: cannot find symbol
  symbol  : class Random
  location: class TestR
          Random random = new Random() ;
                              ^
  TestR.java:6: operator + cannot be applied to Random.nextInt,int
          int randomNumber = random.nextInt(5) + 2;
                                           ^
  TestR.java:6: incompatible types
  found   : &lt;nulltype&gt;
  required: int
          int randomNumber = random.nextInt(5) + 2;
                                               ^
  4 errors
  </code></pre>
  
  <p><br>
  What's going wrong here? </p>