Rewrote generate_next_prime to accept optional limits, start and stop.