random function repaired