import java.util.ArrayList; import java.util.Random; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.IOException; public class Test { public static void main(String[] args)throws IOException { int size = 100; ArrayList<Integer> list = new ArrayList<Integer>(size); for(int i = 1; i <= size; i++) { list.add(i); } Random rand = new Random(System.currentTimeMillis()); while(list.size() > 60) { int num = rand.nextInt(list.size()); BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\Users\\glenn\\Desktop\\trial.txt",true)); // with existing data writer.write(list.remove(num)+ " "); writer.newLine(); writer.close(); } } }
hi to everyone, im a beginner in java , i need some help of you guys if any,
i intend to write a generated numbers without repeatition, and my problem is,
if i write it in file with existing data on it... repeatition of numbers occurs ....