开发者

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?


  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[]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜