A utility package for generating, checking, and working with prime numbers
Project description
Prime Number Generator
Overview
prime_generator is a Python package designed to provide comprehensive utilities for working with prime numbers. Whether you're doing mathematical research, solving coding challenges, or just exploring number theory, this package offers a range of functions to help you work with prime numbers efficiently.
Installation
Prerequisites
- Python 3.8+
- pip
Install from Source
# Clone the repository
git clone https://github.com/yourusername/prime_generator.git
# Navigate to the project directory
cd prime_generator
# Install the package
pip install .
Install for Development
# Install in editable mode with test dependencies
pip install -e .[test]
Features
Prime Number Checking
- Check if a number is prime
- Efficiently implemented with square root optimization
Prime Number Generation
- Generate prime numbers within a specified range
- Flexible start and end parameters
Advanced Prime Number Operations
- Find the nth prime number
- Compute prime factors of a number
- Count prime numbers in a given range
Usage Examples
Basic Prime Checking
from prime_generator import is_prime
print(is_prime(17)) # True
print(is_prime(4)) # False
Generating Prime Numbers
from prime_generator import generate_primes
# Generate primes between 10 and 20
primes = generate_primes(10, 20)
print(primes) # [11, 13, 17, 19]
Finding Nth Prime
from prime_generator import nth_prime
# Find the 5th prime number
print(nth_prime(5)) # 11
Prime Factorization
from prime_generator import prime_factors
# Get prime factors of 12
print(prime_factors(12)) # [2, 2, 3]
Counting Primes in a Range
from prime_generator import count_primes_in_range
# Count primes between 10 and 20
print(count_primes_in_range(10, 20)) # 4
Error Handling
The package includes comprehensive error handling:
- Raises
ValueErrorfor invalid inputs - Prevents operations on numbers less than 2
- Ensures range validity in generation methods
Performance
- Optimized prime checking algorithm
- Linear time complexity for most operations
- Square root optimization for primality testing
Running Tests
# Requires pytest
pytest tests/
Contributing
Reporting Issues
- Use GitHub Issues
- Provide clear, reproducible examples
- Specify your Python version
Development Guidelines
- Fork the repository
- Create a feature branch
- Write tests for new functionality
- Ensure all tests pass
- Submit a pull request
Performance Considerations
- Best suited for small to medium-sized number ranges
- For extremely large prime number operations, consider specialized libraries
License
MIT License
Future Roadmap
- Support for large prime number generation
- More advanced prime number algorithms
- Additional statistical prime number functions
Disclaimer
This package is intended for educational and computational purposes. Always verify critical mathematical computations.
Acknowledgments
Inspired by the beauty of number theory and the joy of mathematical exploration.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prime_number_generator-0.1.0.tar.gz.
File metadata
- Download URL: prime_number_generator-0.1.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34b8a2fb30b4b6f59b9746c697c835df8f02c8cb25b1b4dbabc1e1422e037ed1
|
|
| MD5 |
65b8821e8375e2c335ff07650388bbf2
|
|
| BLAKE2b-256 |
c6b4db8144e91e3de831bccb4c634fd3494ff4523585e830cdeadb2d301585ab
|
File details
Details for the file prime_number_generator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: prime_number_generator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47cc868eedddc3336e297f48259d64f99ae109d2f831601cdcb5cc18955ffea2
|
|
| MD5 |
7669b78a45884eb3df3e1ca57c74c0e0
|
|
| BLAKE2b-256 |
9d93c6e66dcf2c88a7d45aa9b1a384d4be3e4840db6d3f217767b946f89db568
|