quick-is-prime
Test if a number is prime in constant time, using a cached Sieve of Eratosthenes. This is especially helpful to test many numbers' primality.
Install
$ npm install quick-is-prime
var isPrime = require('quick-is-prime');
Usage
isPrime(47)
isPrime(48)
isPrime(61)
isPrime(100)
isPrime(9998903)
isPrime(9893899)
This module uses a cached Sieve of Eratosthenes for constant time lookup. A new one will be automatically generated if the number you're testing is larger than the currently cached sieve's upper bound.
For best results, check primes highest to lowest. Or alternatively, if you know what the upper bound will be, just check that first to not be concerned with the order.
Tests
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
To test code coverage:
$ npm run cover