repaired the random function