Skip to content

Instantly share code, notes, and snippets.

@Dimanaux
Last active August 30, 2018 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dimanaux/115d9f0de53445e65e49a9f022bb1f02 to your computer and use it in GitHub Desktop.
Save Dimanaux/115d9f0de53445e65e49a9f022bb1f02 to your computer and use it in GitHub Desktop.
How I generate arrays for semester work
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;
public class InputGenerator {
public static void main(String[] args) throws IOException {
Random random = new Random();
int[] fileSizes = new int[random.nextInt(50) + 50];
for (int i = 0; i < fileSizes.length; i++) {
fileSizes[i] = random.nextInt(100_000) + 100;
}
FileWriter fileWriter;
for (int i = 0; i < fileSizes.length; i++) {
File file = new File("./res/file" + i + ".txt");
file.createNewFile();
fileWriter = new FileWriter(file);
for (int j = 0; j < fileSizes[i]; j++) {
fileWriter.write(String.valueOf(random.nextInt()) + " ");
}
fileWriter.close();
}
}
}
@kehtolaulu
Copy link

this saved my life

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment