I got what i want but for the purpose of learning i was wondering for different methods.
Mine does fine on a short document but if i wanted the lines of a book back in random order then it would take forever.
- PrintWriter output;// = createWriter("output.txt");
- int[] openList;
- void setup() {
- output = createWriter("output2.txt");
- String[] lines = loadStrings("lines.txt");
- openList = new int[lines.length];
- // fill open list with a id for every line
- for(int i=0; i<lines.length; i++){
- openList[i] = i;
- }
- int count = 0;
- while(count < lines.length){
- int number = int(random(0, lines.length));
- if(openList[number] != -1){
- output.println(lines[number]);
- openList[number] = -1;
- count ++;
- }
- }
- output.flush();
- output.close();
- exit();
- }
1
