Skip to content

Instantly share code, notes, and snippets.

@Glutexo
Created February 22, 2015 13:14
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 Glutexo/9c3497fbb847a7b45059 to your computer and use it in GitHub Desktop.
Save Glutexo/9c3497fbb847a7b45059 to your computer and use it in GitHub Desktop.
Creates a file filled with random content.
#!/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