Fix bug with random number generation