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 picked and output to a text file. any ideas? how would i verify that it is indeed random?
+1
A:
- 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[]
fredley
2010-08-25 23:07:59
Don't forget to leave the last line out of the string array.
Arnold Spence
2010-08-25 23:27:19