Crates.io | codemonk-primes-cli |
lib.rs | codemonk-primes-cli |
version | 1.0.4 |
source | src |
created_at | 2024-02-07 20:06:27.546339 |
updated_at | 2024-02-07 20:23:30.774123 |
description | A command-line utility for finding prime numbers |
homepage | https://www.seanmacdonald.ca/posts/primes |
repository | https://github.com/sean9999/primes-cli/ |
max_upload_size | |
id | 1130932 |
size | 14,740 |
Primes CLI is a binary called primes
, exposing a family of subcommands including primes near
, primes between
, which are all about finding small prime numbers in a certain range (0 to 18,446,744,073,709,551,615 on 64 bit machines, o to 4,294,967,295 on 32 bit). The basic mechanics leverage Sieve Of Eratosthenes and Prime Number Theorem, with optimisations to make it fast.
It is occassionally useful to have a quick way to find a prime number near a particular value. I personally like to use prime numbers in cron-jobs, systemd timers, timeout settings, cache TTLs, and anywhere where there might be a risk of Thundering Herd Problem. It was mainly built for fun.
The command primes
by itself does nothing useful, except produce the help screen (equivilant to primes help
).
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 # exits with error: not a number
Takes two numbers (unsigned integers) and returns all the primes in that range, inclusive, so:
$ primes between 17 29 # returns 17,23,29
Goes all the way to the bottom, so:
$ primes beneath 25 # returns 2,3,5,7,11,13,17,19,23
Basic primality test:
$ primes is 50 # returns no
$ primes is 53 # returns yes