Skip to content

Instantly share code, notes, and snippets.

@metacritical
Last active July 12, 2021 13:32
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 metacritical/14eab0b3963df9a1c41b0a3f7eda556b to your computer and use it in GitHub Desktop.
Save metacritical/14eab0b3963df9a1c41b0a3f7eda556b to your computer and use it in GitHub Desktop.
Create a text file with random sentences of a specific size in bytes.
#Create a random sentence file of spcified size.
#Usage : ruby sentence.rb 100000000 #In bytes.
DICT="/usr/share/dict/words"
words = File.read(DICT).split(' ')
maxsize = ARGV[0].to_i || 10000000000
current_size = 0
f = File.open('testfile.txt', 'a')
char = %w(| / - \\).cycle
while current_size < maxsize
random = rand(10...30)
selection = words.sample(random)
sentence = selection.join(" ") + "\n"
current_size = current_size + sentence.bytesize
f.write(sentence)
print "\b" + "#{char.next}"
end
puts " Bytes Written : #{current_size}"
f.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment