You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
alistair
c400cdb1a9
|
4 years ago | |
---|---|---|
Makefile | 4 years ago | |
README.md | 4 years ago | |
lipsum.c | 4 years ago |
README.md
Lipsum.c
Generates a random string of words of given length using UNIX words file.
Dependencies
- Unix words file at
/usr/share/dict/words
or /usr/dict/words
. This should exist in most UNIX-like operating systems.
Usage
lipsum <num words>
Explanation
It is a somewhat verbose C implementation of the following python function:
import os
import random
def lipsum(num_words):
if os.path.exists('/usr/share/dict/words'):
file_name = '/usr/share/dict/words'
elif os.path.exists('/usr/dict/words'):
file_name = '/usr/dict/words'
else:
return 1
with open(file_name, 'r') as word_file:
words = word_file.readlines()
for i in range(num_words):
print(words[random.randint(0, len(words))], end=' ')
return 0