title: How to do a random-and-unique generator?
body: <p>I already wrote a random generator which take arguments a and b, where a is minimun and b is maximum value, like this randomGenerator(int a, int b)</p>
  
  <p>What I want to do next is: Using a loop, then generate unique number from a to b. Example:</p>
  
  <pre><code>I want to have 8 unique numbers,
  int a = 1;
  int b = 10;
  int value;
  </code></pre>
  
  <p>If I do the loop, there is a high % that same number will appear more than once. Any idea how to do it?</p>
  
  <p>My own way is:</p>
  
  <pre><code>while(int i &lt;= 8){
    randomGenerator(a,b);
    // if value is not in array, then insert into array
  }
  </code></pre>
  
  <p>I am stuck at the comment part. Is there any way to check if a variable is exists in an array?</p>
  
  <p>Edit, based on nailxx's answer, what I understand is:</p>
  
  <ul>
  <li><p>take the list from a to b (if follow my example, 1 - 10)</p></li>
  <li><p>"shuffle" it</p></li>
  <li><p>take the first 8 items. Is that what you mean?</p></li>
  </ul>
  
  <p>In java world, is there a "shuffle" function or I need to create my own?</p>