Skip to content

Instantly share code, notes, and snippets.

@asela38
Last active May 16, 2018 05:01
Show Gist options
  • Save asela38/41e5d6bdc141789f49055498eb4d2cf7 to your computer and use it in GitHub Desktop.
Save asela38/41e5d6bdc141789f49055498eb4d2cf7 to your computer and use it in GitHub Desktop.
Generate file with 1 Billion Integers between 0 and 1000
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.IntStream;
class OneBillionIntegerFileGenerator {
public static void main(String[] args) throws IOException {
try (BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(new FileOutputStream("numbers_1B.in")))) {
IntStream.generate(() -> 1000).map(ThreadLocalRandom.current()::nextInt).limit(1_000_000_000).forEach(i -> {
try {
writer.write(i + "\n");
} catch (IOException e) {
throw new IllegalStateException();
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment