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.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

primegenerator-1.2.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: primegenerator-1.2.1.tar.gz
  • Upload date:
  • Size: 9.8 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.1.tar.gz
Algorithm Hash digest
SHA256 422e3e7aa84b3a67ccc68760bd33d22ee70556cb2588a0f82c22315cce61c7a4
MD5 ec9b923177ae5d906130eccc00b6349f
BLAKE2b-256 71ad75a968ca7364b6560b14a7a68eaaa9cb6b2c0e6a00220c9dd399f144c949

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for primegenerator-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46df587134f18deb543149df9d79e88f091e7bad8b79f59dad53e50120e4efdd
MD5 8b45030b40701be137862ea94f7500a0
BLAKE2b-256 1471f005fd46360b6be82c61b5635a5e5eb1578fd8690976d28611700e7c5c0d

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