in reply to Re: Simple primality testing
in thread Simple primality testing

My original requirements were for primes with 7-8 digits, or more generally, those that can be represented by a long.

testing whether it's a prime and then generating tens and hundreds more until you accidentaly tramp over a prime sounds horribly inefficient to me.

Surprisingly it doesnt take very long at all for my particular task. But you are right it isn't efficient. But efficiency in this particular case is not required at all. If the program takes a few seconds then fine, but as it is it finishes in a heartbeat.

---
$world=~s/war/peace/g

Replies are listed 'Best First'.
Re^3: Simple primality testing
by Jenda (Abbot) on Nov 23, 2005 at 14:18 UTC

    I expected slightly smaller "small primes" :-) And I stand corrected regarding the sparseness of primes. Thanks, you never stop learning :-)

    (For a minute I thought whether it wouldn't be better to generate just one random number and then keep subtracting/incrementing until you find a prime, so that the algorithm is garanteed to finish, but that's not a good idea. Primes are not evenly distributed so some would come up more often than others.)

    Jenda
    XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented.