A random number generator based on shuffled English words, their ASCII values, and the current epoch time to create highly randomized outputs
Project description
random_algorithm
A very simple random algo made while thinking too much about it
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
0
or1
), which can sometimes be difficult to produce with traditional randomization methods.
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.0.0
You can import and use the library in your Python code like this :
from random_algorithm import gen_random
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}")
Note that we also export the internal function ascii_reduce()
:
ascii_reduce(word, index)
: Takes a word in input (ex "github") and an index (can be any positive number). It then reduces the word to a single number (returns an int).
Handling errors
gen_random()
will raise the following exceptions if invalid inputs are provided :
TypeError
: Raised whendesired_size
is not an integer.ValueError
: Raised whendesired_size
is less than 1.
[!WARNING]
The code works fine but isn't the most optimized ever.
Generating huge numbers will take a lot of time ! I you really need a big random number, call the function multiple times with low numbers (ex 1 or 2) and concatenate the results
How it works
- Word shuffling : The words from
wordlist.txt
are 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
0
and1
can be generated using the current epoch time modulo operations.
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
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
Hashes for random_algorithm-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c4af370535b93829227f35ded487f8f13b53f764dd596338adb1befecbc7412 |
|
MD5 | 111ddf6377ee2e037c52976cd799b5b5 |
|
BLAKE2b-256 | 3afd174265226a06b517156b6a290162edaac2a883e258e21a560f6d78637773 |