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 generator!
        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 generator and will keep going past the seed point!
        break

Lowest common multiplier:

from primegenerator import lcm
numbers = [2,3,4]
assert lcm(numbers) == 12

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

primegenerator-1.0.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

primegenerator-1.0.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for primegenerator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0c11f9e57c32764b00986480c1fec46aa2ecebd82d2fbf5e542ccc7b4eda98d0
MD5 e65653927fc53415d333b9f2b9e211a2
BLAKE2b-256 fd6a992ed3f3a057e9993cf9380f47b9fa97bed52b471b931b85b7bafe79e414

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for primegenerator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9d89b5ff30e5dce60f434cbc8cb6b81ae3897d2c9a161d511620061656e8f3b
MD5 1fc35204c6e6a6275b367d535e62bd3d
BLAKE2b-256 3d5904df5ace6a25dfb071d58b2a4c56ace76da9a0867d9e595bc400fd169d52

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