Changed the primitive random generator functions to use closures.