A massive overhaul to support random output.

This addresses issue #2.