title: Java - generate Random range of specific numbers without duplication of those numbers - how to?
body: <p>Sounds simple enough...but I've been plugging away at this, trying to find the one and all solution.</p>
  
  <p>For a range of numbers, say <b>1-12</b>, I want to generate a random sequence within that range, <strong>and</strong> include <b>1</b> and <b>12</b>.</p>
  
  <p><b>I don't want duplicate numbers though</b>.</p>
  
  <p>So I would want something like this - 3,1,8,6,5,4 ..and so on, every number from 1-12.</p>
  
  <p>Then I want to put these random numbers into an <code>Array</code> and use that array to 'randomly' select and display some items (like inventory pulled from database) on a jsp page.</p>
  
  <p>The problem with what I've tried thus far, is that there are a lot of <b>duplicate</b> numbers being generated...or, not <b>ALL</b> of the numbers are chosen.</p>
  
  <p><strong>Is there a simple solution to this problem?</strong></p>
  
  <hr>
  
  <h2><b>Edit</b></h2>
  
  <p><b>Test#1 using <code>Collections</code> and <code>shuffle()</code> method -</b></p>
  
  <pre><code>ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;(10);
  for(int i = 0; i &lt; 10; i++)
  {
    list.add(i);
  }
  Collections.shuffle(list);
  
  String[] randomNumbers = (String[])list.toArray();
  
  for(int i = 0; i &lt; 10; i++)
  {
    out.print(randomNumbers[i]+"&lt;br&gt;");
  }
  </code></pre>
  
  <p>The result was a sequence with duplicate values -<br>
  chose = 3<br>
  chose = 8<br>
  chose = 7<br>
  chose = 5<br>
  chose = 1<br>
  chose = 4<br>
  chose = 6<br>
  chose = 4<br>
  chose = 7<br>
  chose = 12<br></p>
  
  <p><b>Test #2 - using Random math class</b></p>
  
  <pre><code>int max = 12;
  int min = 1;
  
  int randomNumber = 0;
  
  String str_randomNumber = "";
  
  for(int i=0; i&lt;10; i++) {
      //int choice = 1 + Math.abs(rand.nextInt(11));
      int choice = min + (int)(Math.random() * ((max - min) + 1));
  
      out.print("chose = "+choice+"&lt;br&gt;");
  }
  </code></pre>
  
  <p>The result was just like using <code>Collections.shuffle()</code>.</p>