more general functions for rand and time and modified user library