Last active
May 16, 2018 05:01
-
-
Save asela38/41e5d6bdc141789f49055498eb4d2cf7 to your computer and use it in GitHub Desktop.
Generate file with 1 Billion Integers between 0 and 1000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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