Primes
primes is a command-line interface for finding prime numbers, using the Sieve of Eratosthenes. It’s a simple example of a Rust program and how darned fast Rust can be. I use it often to find primes for use in cache expiries or cronjob periods, in an effort to avoid the Thundering Herd problem. When I come across arcane values like 1009
in config files, I know I’ve been there. This is useful as quick verification that I’ve already reviewed a system, as nobody else is insane enough to set a TTL to a godforsaken value like 3593
when 3600
would do. Also, I’m sorry but it’s true. Prime numbers are very, very sexy. I dare you to install this utility and not have a grand old time.
Primes Near
primes near
takes one number as input and returns the nearest prime lower than that number, and the nearest prime higher. If the number you give it is itself prime, it returns 3 numbers
primes near 25 # returns 23,27
primes near 13 # returns 11,13,17
primes near banana # panics, because banana is not a number
Primes Between
Takes two numbers (unsigned integers) and returns all the primes in that range, inclusive:
primes between 17 29 # returns 17,23,29
primes between 65000 65100 # returns 65003,65011...65089,65099
Getting started
To install, you must first have cargo. Then do:
cargo install primes-cli