Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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