fix bug with random number generator