Last active
July 12, 2021 13:32
-
-
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.
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
#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