Pyrandom2pm is a fun package to generate random results. This could be used for random number generation, using it answer your questions using 8-ball, and other unsure scenarios.
Project description
Pyrandom2pm
Pyrandom2pm is a package that adds four random output generators through function calls. The package includes a random number generator, a magic 8-ball that gives random responses to given questions, a dice roll that allows the user to roll up to two dice, and a coin flip that allows for multiple coin flips in one call. Automatic pytests have been created for testing for each commit on github.
How to install and use this package
The module can be installed through normal pip installation syntax:
pip install pyrandom2pm
-
import pyrandom2pm
Instead, you can follow the following steps to install the package in a virtual environment.
- Create a pipenv-managed virtual environment and install the latest version of your package installed:
pipenv install pyrandom2pm
. (Note that if you've previously created a pipenv virtual environment in the same directory, you may have to delete the old one first. Find out where it is located with thepipenv --venv command
.) If you don't know about pipenv, you can find more information such as installation and usage here: pipenv document - Activate the virtual environment:
pipenv shell
. - Create a Python program file that imports your package and uses it, and include:
import pyrandom2pm
- Run the program on the terminal:
python your_pythonfile_name.py
. - Exit the virtual environment:
exit
.
The following are the four functions of the module with their accepted parameters:
pyrandom2pm.randomNum(min, max): Takes positive or negative integer inputs min
and max
as a parameter. The function returns a random integer between min
and max
inclusive.
# example use-case
min = 3
max = 100
print(pyrandom2pm.randomNum(min, max))
Example Output
$ 45
pyrandom2pm.randomDice(num_dice, num_sides): Takes two integer inputs num_dice
and num_sides
as parameters. num_sides
is the number of sides on the dice where only three valid dice sizes are taken: six sides, twelve sides, and twenty sides. num_dice
is the number of dice to be rolled, which can be either one or two. The function will return the dice roll or the sum of the dice roll if two dice are used.
# example use-case
num_dice = 2
num_sides = 6
roll = pyrandom2pm.randomDice(num_dice, num_sides)
print(roll)
Example Output
$ 9
pyrandom2pm.randomCoin(num_flip): Takes an integer input num_flip
as a parameter. num_flip
represents the amount of coin flips a user would like to do. The default value of num_flip
is 1
. The function returns a string of all the coin flip results.
# example use-case
num_flip = 3
flipResults = pyrandom2pm.randomCoin(num_flip)
print(flipResults)
Example Output
$ Heads Heads Tails
pyrandom2pm.random8ball(string): Takes a string input string
as a parameter. If the input string ends with a "?"
, the 8ball will randomly return a yes
answer, a no
answer, or a noncommital
answer. If the string does not end with "?"
, the function returns "That was not a question"
.
# example use-case
string = "Will I pass SWE with Professor Bloomberg?"
answer = pyrandom2pm.random8ball(string)
print(answer)
Example Output
$ Ask again later
More examples can be found at test_pyrandom2pm.py in the tests folder:
python test_pyrandom2pm.py
How to contribute
To contribute, please fork and clone from our public GitHub repository. The source code are in src/pyrandom2pm
. To allow the system to automatically update the new version and avoid delivery error, increment the version
in pyproject.toml
to indicate a new version. Pull requests will be considered one by one, so a contributor will have change the version number again if there is a new version released while waiting for the pull request to be merged.
Building and testing the package recommends using a virtual environment.
- Install pipenv:
pip install pipenv
- Create a virtual environment and install dependencies in
Pipfile
:
pipenv install
- Activate the virtual environment, using:
pipenv shell
- Make changes to the package and make a pull request, and remember to increment the
version
inpyproject.toml
to indicate a new version.
PyPI Link
Authors and Githubs
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 pyrandom2pm-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de49cca4d779d594eeab43c8c0207e554649819177f47cc7a9a2239e251d32a8 |
|
MD5 | cc239f438f8eb0a6ed8801d123ee9744 |
|
BLAKE2b-256 | e8e9e8441acc6913f67e5229ffb13f3a7f9044125868b149cc15eef30b4bd5b7 |