Created
February 22, 2015 13:14
-
-
Save Glutexo/9c3497fbb847a7b45059 to your computer and use it in GitHub Desktop.
Creates a file filled with random content.
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
#!/usr/bin/env ruby | |
require 'securerandom' | |
TARGET_FILE_NAME = "random-file.iso" | |
TARGET_FILE_SIZE = 4707319808 # DVD-RW | |
CHUNK_SIZE = 1000000 # 1 MB | |
file = File.new TARGET_FILE_NAME, 'w' | |
bytes_written = 0 | |
bytes_remaining = TARGET_FILE_SIZE | |
begin | |
chunk_size = if bytes_remaining > CHUNK_SIZE then CHUNK_SIZE else bytes_remaining end | |
file << SecureRandom.random_bytes(chunk_size) | |
bytes_written += chunk_size | |
bytes_remaining -= chunk_size | |
end until bytes_written == TARGET_FILE_SIZE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment