prime {primes} | R Documentation |
generate prime numbers or test whether a sequence of numbers you have are prime or not.
is_prime(x) generate_primes(min = 0, max)
x |
an integer vector containing elements you want to determine the primality of. |
min |
the value to generate primes from. |
max |
the maximum value to generate prime numbers up to. |
is_prime
and generate_primes
rely on Wilson's theorem to test for a number's primality;
as primality algorithms go, this is actually a very slow approach - in theory. In practice, because of the
limits R institutes around integer sizes, it's fast enough for our needs. For example, 10m numbers, all 2^30-sized,
can be tested for primality using this package in 100ms.
#Test for primality is_prime(1299827) # [1] TRUE generate_primes(max =12) # [1] 2 3 5 7 11