Fixed bug with random number generation