Skip to content

Instantly share code, notes, and snippets.

@jlsandell
Created June 10, 2011 15:45
Show Gist options
  • Select an option

  • Save jlsandell/1019103 to your computer and use it in GitHub Desktop.

Select an option

Save jlsandell/1019103 to your computer and use it in GitHub Desktop.
Baconified Lorem Ipsum
from random import sample, randint, choice
MORSELS = ('pork', 'hamburger', 'sirloin', 'fatback', 'bacon', 'shankle',
'tenderloin', 'pig', 'ribeye', 'loin', 'strip', 'chicken',
'meatloaf', 'hock', 'ground', 'turkey', 'chop', 'sausage',
'jowl', 'ham', 'beef', 'tip', 'pancetta', 'tail', 'venison',
'belly', 'rump', 'drumstick', 'jerky', 'ball', 'pastrami',
'shank', 'tritip', 'flank', 'salami', 't-bone', 'spare',
'bresaola', 'corned', 'tongue', 'shoulder', 'short', 'cow',
'ribs', 'chuck', 'biltong', 'swine', 'meatball', 'steak',
'round')
COMMON_P = u'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
COMMON_WORDS = ('lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur',
'adipisicing', 'elit', 'sed', 'do', 'eiusmod', 'tempor',
'incididunt', 'ut', 'labore', 'et', 'dolore', 'magna',
'aliqua')
def sentence():
"""
Returns a randomly generated sentence of bacon ipsum text.
The first word is capitalized, and the sentence ends in either a period or
question mark. Commas are added at random.
"""
s = u', '.join(
[u' '.join(sample(MORSELS, randint(3, 12))) for i in xrange(randint(1, 5))]
)
return u'%s%s%s' % (s[0].upper(), s[1:], choice('?.'))
def paragraph():
"""
Returns a randomly generated paragraph of bacon ipsum text.
The paragraph consists of between 1 and 4 sentences, inclusive.
"""
return u' '.join([sentence() for i in xrange(randint(1, 4))])
def paragraphs(count, common=False):
"""
Returns a list of paragraphs as returned by paragraph().
If `common` is True, then the first paragraph will be the standard
'lorem ipsum' paragraph. Otherwise, the first paragraph will be random,
delicious text. Either way, subsequent paragraphs will be random, delicious
text.
"""
return [COMMON_P if common and i == 0 else paragraph() for i in xrange(count)]
def words(count, common=True):
"""
Returns a string of `count` lorem ipsum words separated by a single space.
If `common` is True, then the first 19 words will be the standard
'lorem ipsum' words. Otherwise, all words will be selected randomly.
"""
if common:
word_list = list(COMMON_WORDS)
else:
word_list = []
c = len(word_list)
if count > c:
count -= c
while count > 0:
c = min(count, len(MORSELS))
count -= c
word_list += sample(MORSELS, c)
else:
word_list = word_list[:count]
return u' '.join(word_list)
if __name__ == '__main__':
print sentence()
print '\n'.join(paragraphs(2, True))
print words(50, False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment