Skip to main content

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()

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 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

primegenerator-1.2.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

primegenerator-1.2.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file primegenerator-1.2.0.tar.gz.

File metadata

  • Download URL: primegenerator-1.2.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for primegenerator-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e55cf6a902c108ef65fbe377779af0668585a8811267443307a66547567db408
MD5 5b5e1a911e09bc4738f76130ab36d020
BLAKE2b-256 aec11abf09d02e0734245f948eb33247a7e66989657118da8c1a4289a66b64cf

See more details on using hashes here.

File details

Details for the file primegenerator-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for primegenerator-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f389710521832cda9907963b53578affc01528e66336fa1c2c4b725901c0d68b
MD5 699ad4ddeea061d85a45cdc716f3057c
BLAKE2b-256 4a3aca759a82e0593defccfd8d3a382417cd3fdffc619ab230abc4b67ed7aa94

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page