rand functions moved here