开发者

Java random selection of lines in csv file for output

开发者 https://www.devze.com 2023-01-14 09:23 出处:网络
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

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

精彩评论

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