Fixed bug with random number generator