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

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

primegenerator-1.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

primegenerator-1.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

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

Hashes for primegenerator-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b33c1af6f3e1dcf3c351dbeea56ee8b1f0f44a13eb6be8fbc8e23d626a19378e
MD5 165037b8f39e0e83d3e5b7462557cc79
BLAKE2b-256 fb81a3b15c686b8adf375c10a6fb33e8af185720ce5aa0a42bbcf1ca5cb6f78f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for primegenerator-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2203f07410c059d66272774401e68a0685b894854a4bd00913b7453b3737482c
MD5 c3beb8b468d5d95da897e8cad7daa236
BLAKE2b-256 54da7e9aca5601f5feea461b634399df9f98b7581641882ad99391c74404117e

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