Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import dictionary, random
- def phrase(minwords, maxwords, maxwordlen=None, maxphraselen=None, EXACT_PHRASE_LEN=None):
- """
- If "maxwordlen" and "maxphraselen" are NoneType (Default), then there are no
- limits for max word/phrase length respectively.
- If "EXACT_PHRASE_LEN" is set, "maxphraselen" will be ignored regardless if it is set.
- >>> phrase(3, 5, 10, EXACT_PHRASE_LEN=20)
- 'lymphaemialenadrowel'
- >>> phrase(3, 5, 10, 22)
- 'eatsformicatekoa'
- """
- maxwordlen = float("inf") if maxwordlen == None else maxwordlen
- maxphraselen = float("inf") if maxphraselen == None else maxphraselen
- words = [i for i in dictionary.allwords if len(i) <= maxwordlen]
- while 1:
- final = ''.join([random.choice(words) for i in range(random.randrange(minwords, maxwords+1))])
- if EXACT_PHRASE_LEN:
- if len(final) == EXACT_PHRASE_LEN:
- break
- else:
- if len(final) <= maxphraselen:
- break
- final = final.lower()
- return final
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement