I'm trying to create 10 files with random names and random data.
Each line in the file consists of two integers and represents one "record".
Naming the files and generating random data didn't turn out very difficult.
But for some reason I fail to recognize, while I create 100 records for each file, instead of that each file ends up with 100, or 400, or 1000, or I don't know how many records..I would really appreciate any help!Thanks in advance
here's the code:
public class Comparisons {
public static void main(String args[]){
Random dice = new Random();
String data = "";
int size [] = new int [100];
int [] time = new int[100];
for(int i = 0; i < 100; i++){
size[i] = time[i] = 0;
}
ArrayList<Integer> fileNames = new ArrayList<Integer>();
for (int i = 0; i < 50; i++) {
fileNames.add(i);
}
Collections.shuffle(fileNames);
for(int j = 0; j < 10; j++){
String name = Integer.toString(fileNames.get(j));
Formatter file = null;
try{
file = new Formatter("%s.txt".format("%s.txt",name) );
}
catch(Exception e){
e.toString();
}
for(int i = 0; i < 100;i++){
if(i == 0){
time[i] = dice.nextInt(2);
size[i] = dice.nextInt(20);
}
else{
time[i] = time[i-1] + dice.nextInt(2);
size[i] = dice.nextInt(20);
}
data += time[i] + " " + size[i] +"\n";
}//end for
try{
file.format("%s", data);
}
catch(Exception e){
e.toString();
}
try{
file.close();
}
catch(Exception e){
e.toString();
}
}//end for
}//end of main
}