Helu

A lightweight, zero-dependency Python package for generating random numbers and sequences with a clean, intuitive API.
Features
- 🎲 Easy Random Number Generation - Generate random integers and floats with simple function calls
- 🔢 Unique Number Sequences - Generate lists of unique random numbers within a range
- 📊 Number Ranges - Create sequences of numbers with custom steps
- 🔐 Deterministic Results - Set seeds for reproducible random number generation
- 🚀 Zero Dependencies - Pure Python implementation with no external requirements
- 💡 Type Hints - Full type annotations for better IDE support and type checking
- 📦 Lightweight - Minimal package size and memory footprint
Installation
Via pip (from PyPI)
pip install helu
From Source
git clone https://github.com/yourusername/helu.git
cd helu
pip install .
Development Installation
git clone https://github.com/yourusername/helu.git
cd helu
pip install -e ".[dev]"
Quick Start
from helu import random_int, random_float, number_range, unique_numbers, set_seed
print(random_int(1, 100))
print(random_float(0.0, 1.0))
print(unique_numbers(5, 1, 50))
print(number_range(1, 11, 2))
set_seed(42)
print(random_int(1, 100))
set_seed(42)
print(random_int(1, 100))
API Reference
random_int(min_val: int, max_val: int) -> int
Generate a random integer between min_val and max_val (inclusive).
Parameters:
min_val (int): Minimum value (inclusive)
max_val (int): Maximum value (inclusive)
Returns: int - A random integer within the specified range
Raises: ValueError - If min_val > max_val
Example:
from helu import random_int
die_roll = random_int(1, 6)
random_float(min_val: float, max_val: float) -> float
Generate a random float between min_val and max_val.
Parameters:
min_val (float): Minimum value
max_val (float): Maximum value
Returns: float - A random float within the specified range
Raises: ValueError - If min_val > max_val
Example:
from helu import random_float
temperature = random_float(20.0, 25.0)
number_range(start: int, stop: int, step: int = 1) -> List[int]
Generate a list of numbers from start to stop (exclusive) with a given step.
Parameters:
start (int): Starting value (inclusive)
stop (int): Ending value (exclusive)
step (int): Step between values (default: 1)
Returns: List[int] - A list of integers in the specified range
Example:
from helu import number_range
evens = number_range(0, 10, 2)
odds = number_range(1, 10, 2)
unique_numbers(count: int, min_val: int, max_val: int) -> List[int]
Generate a list of count unique random integers within the range [min_val, max_val].
Parameters:
count (int): Number of unique integers to generate
min_val (int): Minimum value (inclusive)
max_val (int): Maximum value (inclusive)
Returns: List[int] - A list of unique random integers
Raises: ValueError - If count > (max_val - min_val + 1)
Example:
from helu import unique_numbers
lottery_numbers = unique_numbers(6, 1, 49)
set_seed(seed: Union[int, float, str, bytes, bytearray]) -> None
Set the seed for the random number generator to produce deterministic/reproducible results.
Parameters:
seed: A seed value (int, float, str, bytes, or bytearray)
Returns: None
Example:
from helu import set_seed, random_int
set_seed(42)
first_run = random_int(1, 1000)
set_seed(42)
second_run = random_int(1, 1000)
assert first_run == second_run
random_choice(sequence: Sequence[Any]) -> Any
Select a random element from a non-empty sequence.
Parameters:
sequence: Any sequence (list, tuple, string, etc.)
Returns: Any - A random element from the sequence
Raises: ValueError - If sequence is empty
Example:
from helu import random_choice
card = random_choice(['Hearts', 'Diamonds', 'Clubs', 'Spades'])
element = random_choice([1, 2, 3, 4, 5])
random_choices(sequence: Sequence[Any], k: int = 1) -> List[Any]
Select k random elements from a sequence with replacement (allows duplicates).
Parameters:
sequence: Any sequence
k (int): Number of elements to select (default: 1)
Returns: List[Any] - A list of k random elements
Raises: ValueError - If sequence is empty or k is negative
Example:
from helu import random_choices
rolls = random_choices([1, 2, 3, 4, 5, 6], k=10)
colors = random_choices(['red', 'blue', 'green'], k=5)
shuffle(sequence: List[Any]) -> None
Shuffle a list in-place using the Fisher-Yates algorithm (modifies original list).
Parameters:
sequence: A list to shuffle (must be a list, not tuple or other sequences)
Returns: None (modifies list in-place)
Raises: TypeError - If sequence is not a list
Example:
from helu import shuffle
deck = [1, 2, 3, 4, 5]
shuffle(deck)
print(deck)
shuffled(sequence: Sequence[Any]) -> List[Any]
Return a shuffled copy of a sequence without modifying the original.
Parameters:
Returns: List[Any] - A shuffled copy of the sequence
Example:
from helu import shuffled
original = [1, 2, 3, 4, 5]
shuffled_copy = shuffled(original)
print(original)
print(shuffled_copy)
random_string(length: int = 10, charset: str = ...) -> str
Generate a random string of specified length using alphanumeric characters (or custom charset).
Parameters:
length (int): Length of the string (default: 10)
charset (str): Characters to use for generation (default: letters + digits)
Returns: str - A random string
Raises: ValueError - If length is negative or charset is empty
Example:
from helu import random_string
code = random_string(8)
token = random_string(32)
custom = random_string(5, 'ABCD')
random_password(length: int = 16, use_special: bool = True) -> str
Generate a secure random password with mixed character types.
Parameters:
length (int): Password length (default: 16, minimum: 4)
use_special (bool): Include special characters (default: True)
Returns: str - A secure random password
Raises: ValueError - If length < 4
Example:
from helu import random_password
password = random_password(20)
simple_password = random_password(12, use_special=False)
weighted_choice(items: Sequence[Any], weights: Sequence[float]) -> Any
Select a random item based on relative weights (probability).
Parameters:
items: Sequence of items to choose from
weights: Sequence of weights (probabilities) for each item
Returns: Any - A randomly selected item
Raises: ValueError - If items/weights empty, mismatched lengths, or sum of weights ≤ 0
Example:
from helu import weighted_choice
roll = weighted_choice([1, 2, 3, 4, 5, 6], [1, 1, 1, 2, 2, 3])
loot = weighted_choice(
['common', 'rare', 'legendary'],
[0.7, 0.25, 0.05]
)
random_ints(count: int, min_val: int, max_val: int) -> List[int]
Generate a list of random integers (batch operation).
Parameters:
count (int): Number of integers to generate
min_val (int): Minimum value (inclusive)
max_val (int): Maximum value (inclusive)
Returns: List[int] - List of random integers
Raises: ValueError - If count is negative or invalid range
Example:
from helu import random_ints
test_data = random_ints(10, 1, 100)
flips = random_ints(100, 0, 1)
random_floats(count: int, min_val: float, max_val: float) -> List[float]
Generate a list of random floats (batch operation).
Parameters:
count (int): Number of floats to generate
min_val (float): Minimum value
max_val (float): Maximum value
Returns: List[float] - List of random floats
Raises: ValueError - If count is negative or invalid range
Example:
from helu import random_floats
x_coords = random_floats(100, 0.0, 100.0)
y_coords = random_floats(100, 0.0, 100.0)
temps = random_floats(30, 15.0, 35.0)
Use Cases
Games & Simulations
from helu import random_int, unique_numbers, random_choice, shuffled, weighted_choice
roll = random_int(1, 6)
cards = unique_numbers(5, 1, 52)
suit = random_choice(['♠', '♥', '♦', '♣'])
deck = list(range(1, 53))
shuffled_deck = shuffled(deck)
loot = weighted_choice(['common', 'rare', 'epic', 'legendary'], [0.6, 0.25, 0.12, 0.03])
Testing & Quality Assurance
from helu import set_seed, random_int, random_ints, random_password
set_seed("test_scenario_001")
test_data = random_ints(10, 1, 100)
test_passwords = [random_password(12) for _ in range(5)]
Data Generation
from helu import random_float, random_floats, number_range, random_string
x_coords = random_floats(100, 0, 100)
y_coords = random_floats(100, 0, 100)
coordinates = list(zip(x_coords, y_coords))
batch_ids = number_range(1000, 1100)
tokens = [random_string(32) for _ in range(10)]
Security & Authentication
from helu import random_password, random_string
user_password = random_password(20, use_special=True)
api_token = random_string(64, 'abcdef0123456789')
session_id = random_string(32)
Shuffling & Randomization
from helu import shuffle, shuffled, random_choice, random_choices
questions = ['Q1', 'Q2', 'Q3', 'Q4', 'Q5']
shuffled_questions = shuffled(questions)
playlist = ['song1', 'song2', 'song3', 'song4', 'song5']
shuffle(playlist)
print(f"Playing: {random_choice(playlist)}")
samples = random_choices(range(1, 100), k=50)
Development
Prerequisites
- Python 3.8 or higher
- pip or poetry
Setup Development Environment
git clone https://github.com/yourusername/helu.git
cd helu
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
Running Tests
pytest
pytest --cov=helu
pytest -v
Code Quality
black src/ tests/
isort src/ tests/
flake8 src/ tests/
mypy src/
Testing
The project uses pytest for testing. All functions are covered with comprehensive unit tests.
pytest
pytest tests/test_generator.py
pytest tests/test_generator.py::test_random_int
pytest --cov=helu --cov-report=html
Performance
Helu is lightweight and performant:
- No external dependencies - Pure Python with standard library only
- Minimal overhead - Simple wrapper around Python's built-in
random module
- Small memory footprint - Minimal package size
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature)
- Commit your changes (
git commit -m 'Add some AmazingFeature')
- Push to the branch (
git push origin feature/AmazingFeature)
- Open a Pull Request
Guidelines
- Follow PEP 8 style guide
- Use Black for code formatting
- Add tests for any new functionality
- Update documentation as needed
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you encounter any issues or have questions:
- Check the GitHub Issues
- Create a new issue with a clear description
- Include Python version and relevant code snippets
Changelog
See RELEASES for version history and changes.
Acknowledgments
- Built with Python's standard library
- Inspired by the need for a simple, lightweight random number generation utility
Made with ❤️ by the Helu Team