truncated-gamma-rvs
A Python package for generating random variates from a truncated gamma distribution.
Installation
pip install truncated-gamma-rvs
Quick Start
from truncated_gamma_rvs import truncgamma_rvs
# Generate 100,000 random variates from a gamma distribution truncated
# to the interval [0, 1000], where the mean is 100 and the standard
# deviation is 1/2 the value of the mean (e.g., the coefficient of variation).
x = truncgamma_rvs(
mean_target = 100,
cv_target = 1/2,
A = 0,
B = 1000,
size = 100000,
random_state = 123)
What is a Truncated Gamma Distribution?
A truncated gamma distribution is a gamma distribution that has been "cut off" at specified lower (A) and upper (B) bounds. This is useful when you need gamma-distributed random variables that must fall within a specific range.
API Reference
truncgamma_rvs(mean_target, cv_target, A, B, size=1, random_state=None)
Generate random variates from a truncated gamma distribution.
Parameters:
mean_target(float): Target mean of the truncated distributioncv_target(float): Target coefficient of variationA(float): Lower bound (≥ 0)B(float): Upper bound (> A)size(int, optional): Number of samples to generate (default: 1)random_state(int, optional): Random seed for reproducibility
Returns:
numpy.ndarray: Array of random samples
TruncatedGamma(alpha, theta, A, B)
Class for working with truncated gamma distributions.
Parameters:
alpha(float): Shape parameter (> 0)theta(float): Scale parameter (> 0)A(float): Lower bound (≥ 0)B(float): Upper bound (> A)
Methods:
truncgamma_m1(): Calculate the first moment (mean)truncgamma_m2(): Calculate the second momenttruncgamma_var(): Calculate the variancetruncgamma_cv(): Calculate the coefficient of variation
Requirements
- Python ≥ 3.9
- numpy
- scipy
Development
git clone https://github.com/wkingc/truncated-gamma-rvs-py-package.git
cd truncated-gamma-rvs-py-package
pip install -e ".[dev]"
python -m pytest
License
MIT License. See LICENSE for details.
Documentation
For a complete usage guide, see https://www.kingcopeland.com/truncated-gamma-rvs-py/.
Citation
If you use this package in your research, please consider citing it:
@software{copeland2026tgammarvs,
author = {Wade K. Copeland},
title = {{truncated-gamma-rvs: A Python package for generating random variates from a truncated gamma distribution}},
url = {https://pypi.org/project/truncated-gamma-rvs/},
version = {0.1.6},
year = {2026}
}
Metadata
Release files for truncated-gamma-rvs 0.1.6
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 |
|---|---|---|---|---|
| truncated_gamma_rvs-0.1.6.tar.gz | 5.7 kB | Without provenance | Details for truncated_gamma_rvs-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| truncated_gamma_rvs-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for truncated_gamma_rvs-0.1.6-py3-none-any.whl |
Total release size: 11.3 kB
Release files / truncated_gamma_rvs-0.1.6.tar.gz
| Download URL | truncated_gamma_rvs-0.1.6.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
31aa10db94059848742a211bd9bf1a8420e1cd318cc09e0aa34fc7cc7dbc8936
|
|
BLAKE2b-256 checksum How to use checksums |
6c878125126b3418b0479e99cac5ed2492636328bd60465e74ed7b5b6d2ee402
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / truncated_gamma_rvs-0.1.6-py3-none-any.whl
| Download URL | truncated_gamma_rvs-0.1.6-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
edf89718a403cfb8184108df09af39563601246285a509f4799e2347461f5e67
|
|
BLAKE2b-256 checksum How to use checksums |
d61a695e5cd8593487d5d9cca50588fc0e9ccfa52e335b0752ccf6b60baf3f1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for truncated-gamma-rvs 0.1.6
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.