in reply to Prime Numbers

The fastest way would be to use a table.

my @primes = (2, 3, 5, 7, 11, 13, 17, 19); sub get_a_prime { return $primes[rand @primes]; } sub get_primes_iter { my $i = 0; return sub { return if $i > $#primes; return $primes[$i++]; }; } print(get_a_prime(), "\n"); my $i = get_primes_iter(); while (my ($prime) = $i->()) { print("$prime\n"); }

Or do you have a more specific criteria?

Replies are listed 'Best First'.
Re^2: Prime Numbers
by CountZero (Bishop) on Dec 10, 2007 at 20:44 UTC
    The very fastest way would be to just grab them from one of the files here!

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James