Learn R Programming

primes (version 0.1.0)

prime: Generate and Test for Prime Numbers

Description

generate prime numbers or test whether a sequence of numbers you have are prime or not.

Usage

is_prime(x)

generate_primes(min = 0, max)

Arguments

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.

Details

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.

Examples

Run this code
# NOT RUN {
#Test for primality
is_prime(1299827)
# [1] TRUE

generate_primes(max =12)
# [1]  2  3  5  7 11
# }

Run the code above in your browser using DataLab