Random number generating method and cleaned up code.