fixed logic to check for negative numbers and generate a random number