fixing bug in random function