changed random function