package cn.edu.seu.ise.dca.analysis.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import cn.edu.seu.ise.dca.util.ExcelReader;
import cn.edu.seu.ise.dca.util.ExcelWriter;

public class RandomSelection {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		List<Integer> generatedNumbers = new ArrayList<Integer>();
		int max = 1477;
		int n = 296;
		Random rand = new Random();
		boolean[] bool = new boolean[max + 1];

		int num = 0;

		for (int i = 0; i < n; i++) {
			do {
				num = rand.nextInt(max + 1);
			} while (bool[num]);

			bool[num] = true;
			
			generatedNumbers.add(num);
		}
		
		System.out.println(generatedNumbers);
		
		//Generate the extracted informations
		
		ExcelReader reader = new ExcelReader("F:\\Temp\\projects_coChanges_all.xls");
		ExcelWriter writer = new ExcelWriter("F:\\Temp\\projects_coChanges_selected.xls");
		List<String> rows = reader.readRows(0);
		writer.addLabels(0, rows);
	
		for(int i = 0; i < generatedNumbers.size(); i++) {
			rows = reader.readRows(generatedNumbers.get(i) + 1);
			writer.addLabels(i + 1, rows);
		}
		writer.close();
		reader.close();
	}

}
