title: generate random numbers without repetition - java
body: <p>i'm writing a program for a complicated mathematical operation. I read numbers from a file, then use these numbers to generate as many as possible of sets of 10 random numbers whose sum is 590 and has 5 even numbers and 5 odd numbers (the sum and number of odd and even is changeable).
  every time I run the code, I get either repeated sets or repeated numbers withing the set.</p>
  
  <p>how to fix this so I have unique sets with 10 unique numbers?</p>
  
  <p>here is my code:</p>
  
  <pre><code> public static void main(String args[])
    {
       List&lt;Long&gt; numbers = new ArrayList&lt;Long&gt;();
    try{
    FileInputStream fstream = new FileInputStream("numbers.txt");
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    while ((strLine = br.readLine()) != null)   {
        numbers.add(Long.valueOf(strLine));
    }
    Long[] selectedNumbers = new Long[10];
    Random r = new Random();
    for (int j =0; j&lt;100000; j++){
        long sum = 0;
        int odd = 0;
        int even = 0;
        for(int i = 0; i &lt; selectedNumbers.length; i++){
            selectedNumbers[i] = numbers.get(r.nextInt(numbers.size()));
            if (selectedNumbers[i] % 2 == 0)
            {
                even++;
            } 
            else
            {
                odd++;
            }
            sum = sum + selectedNumbers[i];         
        }
  
            if (even == 5 &amp;&amp; sum == 590 )
            {
                for(int k = 0; k &lt; selectedNumbers.length; k++)
                {
                    System.out.print(selectedNumbers[k] + "\t");
                }
                System.out.print("\n");
            }
  
  
  
    }
    in.close();
      }catch (Exception e){//Catch exception if any
    System.err.println("Error: " + e.getMessage());
    }
    }
  </code></pre>