A simple coin flip random number generator
Project description
mitchallen.coin
A simple, lightweight Python package that provides a random number generator perfect for simulations, games, and probabilistic applications.
Installation
pip install mitchallen-coin
Quick Start
from mitchallen.coin import flip, heads
# Get a random number between 0.0 and 1.0
result = flip()
print(result) # e.g., 0.7234567890123456
# Get a boolean coin flip result
is_heads = heads()
print(is_heads) # True or False
Usage Examples
Simulate a Coin Flip
from mitchallen.coin import heads
if heads():
print("Heads")
else:
print("Tails")
Random Probability Events
from mitchallen.coin import flip
# 30% chance of rain
if flip() < 0.3:
print("Bring an umbrella!")
else:
print("No rain expected")
Monte Carlo Simulation
from mitchallen.coin import flip
# Estimate pi using Monte Carlo method
inside_circle = 0
total_points = 100000
for _ in range(total_points):
x = flip()
y = flip()
if x*x + y*y <= 1:
inside_circle += 1
pi_estimate = 4 * inside_circle / total_points
print(f"Pi estimate: {pi_estimate}")
Random Selection with Weighted Probabilities
from mitchallen.coin import flip
def choose_outcome(probabilities):
"""Choose an outcome based on probability distribution."""
value = flip()
cumulative = 0
for outcome, prob in probabilities.items():
cumulative += prob
if value < cumulative:
return outcome
return list(probabilities.keys())[-1]
# Game loot drop system
loot = {
"common": 0.5,
"rare": 0.3,
"epic": 0.15,
"legendary": 0.05
}
result = choose_outcome(loot)
print(f"You got: {result}")
API Reference
flip()
Returns a random floating-point number in the range [0.0, 1.0).
Returns:
float: A random decimal number from 0.0 (inclusive) to 1.0 (exclusive)
Example:
from mitchallen.coin import flip
value = flip()
assert 0.0 <= value < 1.0
heads()
Returns True if flip() > 0.5, False otherwise. Useful for simple boolean coin flip simulations.
Returns:
bool: True if the coin flip result is greater than 0.5, False otherwise
Example:
from mitchallen.coin import heads
result = heads()
if result:
print("Heads!")
else:
print("Tails!")
Why mitchallen.coin?
- Simple: Clean API with intuitive functions
- Lightweight: No dependencies
- Tested: Comprehensive test suite ensuring quality and reliability
- Namespace package: Works alongside other mitchallen packages
Contributing
Contributions are welcome! See CONTRIBUTING.md for development setup and guidelines.
License
MIT License - see LICENSE for details.
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 mitchallen_coin-0.1.3.tar.gz.
File metadata
- Download URL: mitchallen_coin-0.1.3.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5157f73681001903e54996860fa5da3fc757beca45e2b5530b303b3157f5f2ee
|
|
| MD5 |
58251b345207edb2620c0c3d88e61683
|
|
| BLAKE2b-256 |
7f987267a9131478588923277301586a4113d54192fbc16da11080e6b810ed45
|
Provenance
The following attestation bundles were made for mitchallen_coin-0.1.3.tar.gz:
Publisher:
publish.yml on mitchallen/python-coin-flip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mitchallen_coin-0.1.3.tar.gz -
Subject digest:
5157f73681001903e54996860fa5da3fc757beca45e2b5530b303b3157f5f2ee - Sigstore transparency entry: 707007251
- Sigstore integration time:
-
Permalink:
mitchallen/python-coin-flip@99354bb062d642e3de7d41e5806e8d56efbfe661 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/mitchallen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@99354bb062d642e3de7d41e5806e8d56efbfe661 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mitchallen_coin-0.1.3-py3-none-any.whl.
File metadata
- Download URL: mitchallen_coin-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fed83cf0f5af3641c186e4a45746a9a5a4f20b03841d27c921be6f11fbbb937e
|
|
| MD5 |
1e89ba58c28ea562c5a3bbcc2b889c21
|
|
| BLAKE2b-256 |
21b45be4869188a42584c52270a309b993b50ccf6222bfdaa1028ab7f1c10ed5
|
Provenance
The following attestation bundles were made for mitchallen_coin-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on mitchallen/python-coin-flip
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mitchallen_coin-0.1.3-py3-none-any.whl -
Subject digest:
fed83cf0f5af3641c186e4a45746a9a5a4f20b03841d27c921be6f11fbbb937e - Sigstore transparency entry: 707007271
- Sigstore integration time:
-
Permalink:
mitchallen/python-coin-flip@99354bb062d642e3de7d41e5806e8d56efbfe661 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/mitchallen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@99354bb062d642e3de7d41e5806e8d56efbfe661 -
Trigger Event:
release
-
Statement type: