1A06CC97-3CA9-4FFC-B82F-182A54E0A867

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

import java.io.

File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RandomOperationsFileGenerator {


public static void main(String[] args) {
File inputFile = new File("input.txt");
Random random = new Random();
List<String> insertions = new ArrayList<>();
List<String> deletions = new ArrayList<>();
List<String> searches = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
int operationType = random.nextInt(3); // 0 =
insert, 1 = delete, 2 = search
int value = random.nextInt(10000);
String operation = "";
switch (operationType) {
case 0:
insertions.add("insert " + value);
break;
case 1:
deletions.add("delete " + value);
break;
case 2:
searches.add("search " + value);
break;
}
}
try (FileWriter writer = new FileWriter(inputFile)) {
for (String insertion : insertions) {
writer.write(insertion + "\n");
}
for (String deletion : deletions) {
writer.write(deletion + "\n");
}
for (String search : searches) {
writer.write(search + "\n");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

You might also like