Java random selection of lines in csv file for output
I want to read in a variable length csv file and randomly select a percentage of lines from the file to be output. For instance if I have 20 lines I would read each line in counting up to 20 the last line will have a number only (the percentage). then figure this percentage from the number of lines read in for instance 10 on the last line would give me 20 * 10% so 2 lines to be randomly pick开发者_运维知识库ed and output to a text file. any ideas? how would i verify that it is indeed random?
- Insert the lines into a
String[]
- Calculate the number of lines you want to select:
int number = (int)(myArray.length * percentage);
- Pick a random sample from the
String[]
精彩评论