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
Test if number is prime:
from primegenerator import PrimeNumbers
assert 5 in PrimeNumbers()
assert 9 not in PrimeNumbers()
Get a specific prime:
from primegenerator import PrimeNumbers
primes = PrimeNumbers(startat1=True)
assert primes[3] == 5
assert primes[3:5] == [5,7]
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
What's New?
v1.3.1
- Slicing supports negative step
v1.3.0
- Get a specific prime with
primes[n]orprimes[n:m]
v1.2.1
test_wrapperimprovements
v1.2.0
n in PrimeNumbers()will test if n is prime
v1.1.0
lcmwill take multiple arguments and find lowest common multiplier. (Previously required a single list or tuple)
v1.0.0
PrimeNumbers()infinite iterator supportingstartat1,.preseed()lcmto find lowest common multipliersieveto return a list of primes
Coming next...
Able to launch a parallel process to pre-calculate the next prime needed on a separate CPU core
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file primegenerator-1.3.1.tar.gz.
File metadata
- Download URL: primegenerator-1.3.1.tar.gz
- Upload date:
- Size: 10.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 |
58f5482a33314bd3916eb6c8454c9b0e7198cca302130dc3d421af0d059c37d4
|
|
| MD5 |
93713af4b2748743ff7bed558ca79608
|
|
| BLAKE2b-256 |
5f8eb68b3973881e994385dd0d146248774c3293edf3ce8405add4f3ec964ae3
|
File details
Details for the file primegenerator-1.3.1-py3-none-any.whl.
File metadata
- Download URL: primegenerator-1.3.1-py3-none-any.whl
- Upload date:
- Size: 10.9 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 |
9c6e7f0eea42c4c8bba6c1534901ab6fcb5144b14de97ca791c1794df15e9d2e
|
|
| MD5 |
b9e8d9c794213bbe57b05c164a31d1fc
|
|
| BLAKE2b-256 |
838074c194aba378f2f879543047274eb689c0dbae882ddb0f8ded21befcf6e8
|