title: Making sure no two random lines are the same.
body: <p>The following code works great for picking random lines from a file. How do I make sure that no two lines occurs since random may repeat the same line again.</p>
  
  <pre><code>BufferedReader reader = new BufferedReader(new FileReader(file));
  List&lt;String&gt; lines = new ArrayList&lt;String&gt;();
  
  String line = reader.readLine();
  while( line != null ) {
      lines.add(line);
      line = reader.readLine();
  }
  
  Random r = new Random();
  int i = 0;
  while(i &lt; 4){
      System.out.println(lines.get(r.nextInt(lines.size())));
      i++;
  }
  </code></pre>