Fast primes generator and related functions
Project description
Introduction
Fast PrimeNumbers
generator which caches previous results across instances.
You usually don't need as many primes as the worst-case - eg for the included lcm
(lowest common multiplier) function.
Also provides a very fast primesieve
if you wish to pre-calculate a large number of primes.
Getting Started
Installation: pip install primegenerator
Main usage:
from primegenerator import PrimeNumbers
primes = PrimeNumbers()
for prime in primes:
... #do something
if ... #beware this is an infinite iterator!
break
Preseed - if you know you need all primes up to n:
from primegenerator import PrimeNumbers
n = 100 #somebignumber
primes = PrimeNumbers.preseed(n)
for prime in primes:
... #do something
if ... #beware this is still an infinite iterator and will keep going past the seed point!
break
Lowest common multiplier:
from primegenerator import lcm
numbers = [2,3,4]
assert lcm(numbers) == 12
assert lcm(3,4,5) == 60
Sieve:
from primegenerator import primesieve
listofprimes = primesieve(maxprime)
Build and Test
Tests are written for pytest in /tests/test_*.py
pip -r tests/requirements.txt
for additional imports required for some tests.
Tests are available on the ADO repository (see link below)
/dev
contains some useful stuff for debugging, profiling and further development and is only available on the ADO repository (see link below)
Contribute
Code repository (ADO): https://dev.azure.com/MusicalNinjas/MikesMath/_git/primes
Homepage: https://dev.azure.com/MusicalNinjas/MikesMath
Coming soon...
assert 31 in primes
assert primes[3] == 5
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file primegenerator-1.1.0.tar.gz
.
File metadata
- Download URL: primegenerator-1.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b33c1af6f3e1dcf3c351dbeea56ee8b1f0f44a13eb6be8fbc8e23d626a19378e |
|
MD5 | 165037b8f39e0e83d3e5b7462557cc79 |
|
BLAKE2b-256 | fb81a3b15c686b8adf375c10a6fb33e8af185720ce5aa0a42bbcf1ca5cb6f78f |
File details
Details for the file primegenerator-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: primegenerator-1.1.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2203f07410c059d66272774401e68a0685b894854a4bd00913b7453b3737482c |
|
MD5 | c3beb8b468d5d95da897e8cad7daa236 |
|
BLAKE2b-256 | 54da7e9aca5601f5feea461b634399df9f98b7581641882ad99391c74404117e |