Implemented rand function. Needs fixing