Initial draft, terribly slow, but it had the core ideas.

Seems to produce random output, so that's a plus.