tags:

views:

13

answers:

1

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: 
  1. Insert the lines into a String[]
  2. Calculate the number of lines you want to select: int number = (int)(myArray.length * percentage);
  3. Pick a random sample from the String[]
fredley
Don't forget to leave the last line out of the string array.
Arnold Spence