Skip to content

Instantly share code, notes, and snippets.

@debrice

debrice/loreming.py

Created Nov 26, 2012
Embed
What would you like to do?
I recently wanted to generate data for a project I'm working on. Lorem ipsum offers a package but I really think it is "oversized" for what I needed: generating random text content that looks human.
import random
def paragraph(min=1, max=20):
def sentence():
nouns = ["time", "person", "year", "way", "day", "thing", "man", "world",
"life", "hand", "part", "child", "eye", "woman", "place", "work", "week",
"case", "point", "government", "company", "number", "group", "problem", "fact"]
verbs = ["be", "have", "do", "say", "get", "make", "go", "know", "take",
"see", "come", "think", "look", "want", "give", "use", "find", "tell", "ask",
"work", "seem", "feel", "try", "leave", "call"]
adjectives = ["good", "new", "first", "last", "long", "great", "little",
"own", "other", "old", "right", "big", "high", "different", "small",
"large", "next", "early", "young", "important", "few", "public",
"bad", "same", "able"]
prepositions = ["to", "of", "in", "for", "on", "with", "at", "by", "from",
"up", "about", "into", "over", "after", "beneath", "under", "above"]
adverbs = ["and", "therefore", "then", "but", "while", "so", "in order to",
"thereafter", "also", "besides", "consequently", "finally", "hence", "in addition",
"However", "furthermore", "meanwhile", "likewise", "instead", "indeed"]
def maker():
words = []
if random.choice([1,0,0]): # 1 out of 3
words.append(random.choice(prepositions))
if random.choice([1,0,0]): # 1 out of 3
words.append(random.choice(adjectives))
words.append(random.choice(nouns))
words.append(random.choice(verbs))
if random.choice([1,0,0]): # 1 out of 3
words.append(random.choice(prepositions))
if random.choice([1,1,0]): # 2 out of 3
words.append(random.choice(adjectives))
words.append(random.choice(nouns))
return words
words = maker()
if random.choice([1,0,0]): # 1 out of 3
words.append(random.choice(adverbs))
words += maker()
return ' '.join(words).capitalize()
sentences = []
for x in range(random.randrange(min,max)):
sentences.append(sentence())
return '. '.join(sentences) + random.choice('??!...')
>>> paragraph(min=1,max=2)
'Part work government therefore number be point?'
>>> paragraph(min=2,max=5)
'Early year take big week. Little day seem small group. Group try public case in addition small fact try place. Young part get bad thing!'
>>> paragraph()
'First way use large day meanwhile government know same case. Person say hand. Man give same person. Above good number feel man. In small part seem group. Old place work bad way. Child leave child. Big child do place then young work see long child. Man call eye thereafter same way want problem. With same place come different problem then great child call place. Different problem make bad point. Thing think man. Number come old place meanwhile to government have different time. Eye take small week. Old place think way therefore person find same world. By eye do large person. Long number know first man.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment