[33007] | 1 | //NAME:Caleb Bird
|
---|
| 2 | //ID: 1289680
|
---|
| 3 | //??References??
|
---|
| 4 |
|
---|
| 5 | import java.io.BufferedReader;
|
---|
| 6 | import java.io.FileReader;
|
---|
| 7 | import java.io.FileWriter;
|
---|
| 8 | import java.util.*;
|
---|
| 9 |
|
---|
| 10 | public class TabRndListGen {
|
---|
| 11 | public static void main(String[] args) {
|
---|
| 12 | try{
|
---|
| 13 | if (args.length != 3){
|
---|
| 14 | System.out.println("Usage: RandomItemSelecta <inputFilename> <outputCount> <outputFilename>");
|
---|
| 15 | }
|
---|
| 16 | else{
|
---|
| 17 | String inputFilename = args[0];
|
---|
| 18 | int outputCount = Integer.parseInt(args[1]);
|
---|
| 19 | String outputFilename = args[2];
|
---|
| 20 |
|
---|
| 21 | BufferedReader buf = new BufferedReader(new FileReader(inputFilename));
|
---|
| 22 | FileWriter fw = new FileWriter(outputFilename);
|
---|
| 23 | //FileWriter fw = new FileWriter("hathiRndIDList.txt");
|
---|
| 24 | //BufferedReader buf = new BufferedReader(new FileReader("hathiDocIDList.txt"));
|
---|
| 25 |
|
---|
| 26 | ArrayList<String> list = new ArrayList<String>();
|
---|
| 27 | ArrayList<String> subList;
|
---|
| 28 | String line = null;
|
---|
| 29 |
|
---|
| 30 | //Add items to Array
|
---|
| 31 | while ((line = buf.readLine()) != null) {
|
---|
| 32 | list.add(line);
|
---|
| 33 | }
|
---|
| 34 | //randomize list
|
---|
| 35 | Collections.shuffle(list);
|
---|
| 36 |
|
---|
| 37 | //Take <outputCount>
|
---|
| 38 | subList = new ArrayList<String>(list.subList(0,outputCount));
|
---|
| 39 |
|
---|
| 40 | //Write these to new file
|
---|
| 41 | for(int i =0; i < subList.size(); i++){
|
---|
| 42 | fw.write(subList.get(i) + '\n');
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | buf.close();
|
---|
| 46 | fw.close();
|
---|
| 47 | }
|
---|
| 48 | }catch(Exception e){
|
---|
| 49 | e.printStackTrace();
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | // Returns 42474
|
---|
| 54 |
|
---|
| 55 | //REFERNECES
|
---|
| 56 | //https://www.javatpoint.com/java-filewriter-class
|
---|
| 57 | //https://docs.oracle.com/javase/8/docs/api/index.html?java/io/FileWriter.html
|
---|
| 58 | //https://www.geeksforgeeks.org/randomly-select-items-from-a-list-in-java/
|
---|
| 59 | //https://codereview.stackexchange.com/questions/146551/picking-10-distinct-words-randomly-from-list-of-unique-words
|
---|
| 60 |
|
---|
| 61 | //USE RUN-LIST.txt (modify file it reads using $1 (terminal entry variable (filename))
|
---|
| 62 |
|
---|