fixed random number generator code