Committing RandomGenerator patch from Allen King, with a few small changes