fixed the random function