fix a bug in random function