random utilities (Mostly Java Code)