Skip to main content

A comprehensive and high-entropy random number generator library.

Project description

MZRandom: A Comprehensive Random Number Library

MZRandom is a versatile and feature-rich random number library designed for Python. It enhances randomness using multiple entropy sources, supports customizable PRNG algorithms, and provides a robust API for statistical and utility-based random operations.


Features

  • High Entropy: Combines various entropy sources such as system time, OS state, and garbage collection.
  • Customizable PRNG Algorithms: Supports Xorshift1024, PCG64, and ChaCha20.
  • Wide Functionality:
    • Random floats, integers, and sequences
    • Shuffling and sampling
    • Statistical distributions (normal, gamma, etc.)
  • Thread-Safe: Ensures safe operations in multi-threaded environments.

Installation

pip install mzrandom

Usage

Basic Example

from mzrandom import MZRandom

cr = MZRandom(prng_algorithm="pcg64")

# Generate random numbers
print(cr.random())  # Float between 0.0 and 1.0
print(cr.randint(1, 100))  # Random integer between 1 and 100

# Shuffle a list
my_list = [1, 2, 3, 4, 5]
cr.shuffle(my_list)
print(my_list)

# Sample from a population
print(cr.sample([1, 2, 3, 4, 5], 2))

API Reference

Initialization

MZRandom(entropy_sources=None, prng_algorithm="xorshift1024")
  • entropy_sources: Optional list of entropy-generating functions.
  • prng_algorithm: Choose from xorshift1024, pcg64, or chacha20.

Methods

  • Random Numbers:
    • random(): Returns a random float in [0.0, 1.0).
    • randint(a, b): Returns a random integer between a and b (inclusive).
    • randrange(start, stop, step): Random value in a range.
  • Sequences:
    • choice(seq): Random element from a sequence.
    • choices(population, k): k random choices (with replacement).
    • shuffle(x): Shuffles a list in place.
    • sample(population, k): k unique elements.
  • Distributions:
    • normalvariate(mu, sigma): Normal distribution.
    • gammavariate(alpha, beta): Gamma distribution.
    • triangular(low, high, mode): Triangular distribution.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.


License

MZRandom is licensed under the MIT License.


MZRandom: کتابخانه‌ای جامع برای اعداد تصادفی

MZRandom یک کتابخانه قدرتمند و پرکاربرد برای تولید اعداد تصادفی در زبان پایتون است. این کتابخانه با استفاده از منابع متعدد انتروپی و الگوریتم‌های پیشرفته، قابلیت‌های گسترده‌ای ارائه می‌دهد.


ویژگی‌ها

  • انتروپی بالا: ترکیب منابع مختلف مانند زمان سیستم، وضعیت OS و اطلاعات حافظه.
  • الگوریتم‌های قابل تنظیم: پشتیبانی از Xorshift1024، PCG64، و ChaCha20.
  • قابلیت‌های گسترده:
    • تولید اعداد تصادفی اعشاری و صحیح
    • جابجایی و نمونه‌گیری از داده‌ها
    • توزیع‌های آماری (نرمال، گاما و غیره)
  • ایمن در برابر چند رشته‌ای (Thread-Safe): عملیات ایمن در محیط‌های چند رشته‌ای.

نصب

pip install mzrandom

استفاده

مثال ساده

from mzrandom import MZRandom

cr = MZRandom(prng_algorithm="pcg64")

# تولید اعداد تصادفی
print(cr.random())  # عدد اعشاری بین 0.0 و 1.0
print(cr.randint(1, 100))  # عدد صحیح بین 1 و 100

# جابجایی یک لیست
my_list = [1, 2, 3, 4, 5]
cr.shuffle(my_list)
print(my_list)

# نمونه‌گیری از یک مجموعه
print(cr.sample([1, 2, 3, 4, 5], 2))

راهنمای API

مقداردهی اولیه

MZRandom(entropy_sources=None, prng_algorithm="xorshift1024")
  • entropy_sources: لیستی از توابع تولید انتروپی (اختیاری).
  • prng_algorithm: انتخاب بین xorshift1024، pcg64، یا chacha20.

متدها

  • اعداد تصادفی:
    • random(): عدد اعشاری تصادفی در بازه [0.0, 1.0).
    • randint(a, b): عدد صحیح تصادفی بین a و b (شامل هر دو).
    • randrange(start, stop, step): مقدار تصادفی از یک بازه.
  • دنباله‌ها:
    • choice(seq): یک عنصر تصادفی از دنباله.
    • choices(population, k): k انتخاب تصادفی (با جایگزینی).
    • shuffle(x): جابجایی لیست به صورت درجا.
    • sample(population, k): k عنصر منحصر به فرد.
  • توزیع‌ها:
    • normalvariate(mu, sigma): توزیع نرمال.
    • gammavariate(alpha, beta): توزیع گاما.
    • triangular(low, high, mode): توزیع مثلثی.

همکاری در توسعه

برای همکاری، لطفاً یک Issue باز کنید یا درخواست Pull Request ارسال کنید.


مجوز

MZRandom تحت مجوز MIT ارائه شده است.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mzrandom-1.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mzrandom-1.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file mzrandom-1.0.1.tar.gz.

File metadata

  • Download URL: mzrandom-1.0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for mzrandom-1.0.1.tar.gz
Algorithm Hash digest
SHA256 94621af6456e354d5faaa66c58e59e8136c402fa6c863f876e5e31f5d9da7b86
MD5 793ae4fb683fcc33a3ded574bbef7567
BLAKE2b-256 8c406fd45d201369e03ecefc5981812f4cf03c2cacfb6ed619a212892f98b156

See more details on using hashes here.

File details

Details for the file mzrandom-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mzrandom-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for mzrandom-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fbd967e434cce934f3b1ab1b07c3b99d9e95983dae35333cc81738baef7057cd
MD5 4e80d6f7f042d094cf690d9fbfbdc4dc
BLAKE2b-256 346f5c5574bf73bc6e73d6a6332b901e248611edf69980a0fccecc0849c0eac3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page