fixing random function