random_algorithm
A very simple yet original random algo made while overthinking about randomness
random_algorithm is a Python library that generates random numbers using a novel approach based on English words and the current epoch time. It utilizes ASCII values of shuffled words, reduces them to single digits, and combines these digits to generate a random number of a specified size. This implementation attempts to get as close as possible to true randomness by using time-based factors and word shuffling.
Features
- Generates random numbers based on shuffled English words.
- ASCII values of each word are reduced to single digits.
- Supports dynamic generation of random numbers of any specified size.
- Includes special logic to generate lower numbers (like
0or1), which can sometimes be difficult to produce with traditional randomization methods. - Provides functions to extract seeds based on time and to reduce any number to a single digit.
Usage
Install the package in your repo
pip install random_algorithm
If you use a requirements file, add this line to it :
random_algorithm==1.1.0
You can import and use the library in your Python code like this :
from random_algorithm import gen_random
Example :
Generate a random number with a desired size of 5 digits
random_number = gen_random(desired_size=5)
print(f"Generated random number : {random_number}")
You can also use the following internal functions :
ascii_reduce(word, index):- Takes a word (ex
"github") and an index (can be any positive number) as input. - Reduces the word to a single digit (returns an
int).
- Takes a word (ex
reduce_to_single_digit(n):- Reduces any integer
nto a single digit by summing its digits repeatedly until one digit remains. - For example,
reduce_to_single_digit(9875)would return2.
- Reduces any integer
get_time_seed():- Generates a seed based on the current time and ASCII reduction of character permutations.
Handling errors
gen_random() will raise the following exceptions if invalid inputs are provided :
TypeError: Raised whendesired_sizeis not an integer.ValueError: Raised whendesired_sizeis less than 1.
How it works
- Word shuffling : The words from
wordlist.txtare shuffled on each call to ensure randomness. - Random index : The current epoch time is used to generate a random index into the shuffled word list.
- ASCII reduction : Each word's ASCII values are reduced to single digits and then summed to produce a random number.
- Low numbers handling : A special condition ensures that numbers like
0and1can be generated using the current epoch time modulo operations. -
- Time Seed:
get_time_seed()creates a seed value based on permutations of characters from the current time.
- Time Seed:
Contributing
Feel free to open an issue or a pull request if you want to contribute to this project
How to build ?
py -m pip install --upgrade pip build twine setuptools wheel
py -m build
py -m twine check dist/*
# Optional : publish to test.pypi.org
py -m twine upload --repository testpypi dist/*
# Or to pypi.org
py -m twine upload dist/*
License
This project is licensed under the MIT License - see the LICENSE file for details.
The wordlist comes from from https://github.com/dwyl/english-words.
Authors
- EDM115 - Initial work
Metadata
Release files for random-algorithm 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| random_algorithm-1.1.0.tar.gz | 1.1 MB | Without provenance | Details for random_algorithm-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| random_algorithm-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for random_algorithm-1.1.0-py3-none-any.whl |
Total release size: 2.2 MB
Release files / random_algorithm-1.1.0.tar.gz
| Download URL | random_algorithm-1.1.0.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fe0de2db16d4b00c4d10e234bb014c7aaf5a9995743ce664d95634fc33a077c7
|
|
BLAKE2b-256 checksum How to use checksums |
2d1f4e6c5ef4c9c2d0e4cc8830f9f73796d9c1d70d9188b6ef75d3b9eccf9f19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Release files / random_algorithm-1.1.0-py3-none-any.whl
| Download URL | random_algorithm-1.1.0-py3-none-any.whl |
|---|---|
| Size | 1.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
18c17ae395ae5ca0f075637676e08bc8d885ac9d24ba3783f1f8df1be90b9b46
|
|
BLAKE2b-256 checksum How to use checksums |
997c6fd1c0326e1f709514e66f463c03f3cb2b6e6c800009b81e5e8bdb8f608f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Security for random-algorithm 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.