this code was suppose to prevent any single line from appearing twice for each display, i thought it was ok but later found that it wasnt, i was directed to use the hashset method in combination with my code to prevent that from happening, but it is not consistent, i need a solution to this please
import java.io.*;
import java.util.*;
class RandomSelection {
public static void main(String[] args) {
try{
FileInputStream fstream = new FileInputStream("c:\\filea.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
LineNumberReader ln = new LineNumberReader(br);
int count = 0;
while (ln.readLine() != null){
count++;
}
ln.close();
in.close();
fstream = new FileInputStream("c:\\filea.txt");
in = new DataInputStream(fstream);
br = new BufferedReader(new InputStreamReader(in));
String strLine;
ln = new LineNumberReader(br);
Random mixture = new Random();
HashSet<Integer> usedNums = new HashSet<Integer>();
int numberIndex;
String[] see = new String[count];
int i = 0;
while ((strLine = br.readLine()) != null) {
see[i] = strLine;
i = i + 1;
}
for ( i=1; i <=5; i++) {
do{numberIndex = mixture.nextInt(see.length);
}
while(!usedNums.add(numberIndex) );
System.out.println(see[numberIndex]);
}
ln.close();
in.close();
}
catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
}