fix the random number generation