Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
from random import choice, randint def rb(): return choice([True, False]) def rand(depth=6, t=True): if depth == 0: if t: return "1" else: return "0" else: c = choice(["not", "and", "or"]) if "not" == c: return "(not " + rand(depth-1, not t) + ")" elif "and" == c: if t: return "(and " + rand(depth-1, True) + " " + rand(depth-1, True) + ")" else: if rb(): return "(and " + rand(depth-1, rb()) + " " + rand(depth-1, False) + ")" else: return "(and " + rand(depth-1, False) + " " + rand(depth-1, rb()) + ")" elif "or" == c: if not t: return "(or " + rand(depth-1, False) + " " + rand(depth-1, False) + ")" else: if rb(): return "(or " + rand(depth-1, rb()) + " " + rand(depth-1, True) + ")" else: return "(or " + rand(depth-1, True) + " " + rand(depth-1, rb()) + ")" if __name__ == '__main__': print rand()
This paste will be private.
From the Design Piracy series on my blog: