Clear questions and runnable code get the best and fastest answer 

PerlMonks 
Comment on 
( #3333=superdoc: print w/ replies, xml )  Need Help?? 
There is no way of predicting what the next prime number is, given any other number. If there was, then current cryptography methods wouldn't work. All prime number generators are, for the most part, variations on brute force. The method you're looking at is probably as good as any. Huh?!? You're joking, aren't you? The same fact that you say "all prime number generators are, for the most part, variations on brute force" is in contradiction with the claim that "there is no way of predicting what the next prime number is, given any other number". More precisely if I have any isprime() sub, e.g. (I'm not posting a better one for others already have, and even better ones are available elsewhere.) or the witty (this is Abigail's  who else?) then a sub like this: would answer the OP's question. Important: not only primality testing algorithms do exist, but fast ones exist too. What in some sense there is "no way" to do is to factorize a composite number which is a different problem. But really even for the latter problem there are perfectly deterministic algorithms. "Only" it is believed to be computationally "hard" (in a mathematically precise sense), whereas the former is not. It is on this last conjecture (not proved yet!) that many cryptography methods rely. Since the OP did not specify the size of a problem, but gave an example with small numbers, an effective answer in terms of some efficient sieving algorithm can be given. In reply to Re^4: a close prime number
by blazar

