Skip to main content

Fast primes generator and related functions.

Project description

Introduction

Fast primes 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 primes
primenums = primes()
for prime in primenums:
    ... #do something
    if ... #beware this is an infinite generator!
        break

Preseed - if you know you need all primes up to n:

from primegenerator import primes
n = 100 #somebignumber
primenums = primes.preseed(n)
for prime in primenums:
    ... #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 primenums
assert primenums[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-0.10.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

primegenerator-0.10.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for primegenerator-0.10.2.tar.gz
Algorithm Hash digest
SHA256 41ac01442da5d4c31213b140dab4ef2eeafe5e0084a231738e01c1448818d162
MD5 ec7c097a4881833c9acf8805fa5c0479
BLAKE2b-256 f2cfeafe812fe744e77d067422d82941bdd52a0c67d3e308f01a3fc3fc81f567

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for primegenerator-0.10.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4dbce866e48350b5301fcda89b174a7d39ae04aedbbd57e69535e671583e521a
MD5 b297bd4c0e1bf25b400398ce0e7c98d3
BLAKE2b-256 aa18a0c424e951fe75726d80daeb3ef695ef806a59440a18b012bb35f6e2c4af

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