Generates a random number based on the specified criteria.