Skip to main content

Generate Bernoulli distributed values using Linear Congruential Generator (LCG)

Project description


📌 Description

Generate Bernoulli Distributed Values using Linear Congruential Generator (LCG)

brnldist is a lightweight Python package that simulates Bernoulli-distributed random variables using values generated by a Linear Congruential Generator (LCG).

It combines the simplicity of LCG for pseudo-random number generation with a Bernoulli distribution threshold to produce a sequence of 0s and 1s.

This is useful for simulations, basic statistical modeling, or understanding how pseudo-random processes work behind random variable generation.


⚙️ How It Works

  1. Uses LCG to generate a sequence of pseudo-random integers:

    $$ X_{n+1} = (a \cdot X_n + c) \mod m $$

  2. Normalizes each LCG value to the interval [0, 1] by dividing by the modulus m.

  3. Compares each normalized value with a probability threshold p:

    • If the value < p → return 1 (success)
    • Else → return 0 (failure)
  4. Returns a sequence of binary outcomes following a Bernoulli(p) distribution.


📈 Example Output

from brnldist import brnldist
from brnldist import lcg
a=2
c=3
x0=5
m=103
p=0.5
n=10
y, u, x = lcg(a, c, x0, m, p, n)

#Parameters:
        #a (int): LCG multiplier
        #c (int): LCG increment
        #x0 (int): Seed value
        #m (int): LCG modulus
        #p (float): Bernoulli threshold (0 to 1)
        #n (int): Number of values to generate
print("LCG raw values (y):", y)
print("Normalized values (u):", u)
print("Second normalized value u[1]",u[1])
print("Bernoulli output (x):", x)

# y = LCG raw values
# u = normalized values
# u[1] = Second normalized value
# x = Bernoulli (0 or 1) outcomes

👤 Author Rohit Kumar Behera 📧 Email: rohitmbl24@gmail.com 🌐 GitHub: github.com/muinrohit 🏠 Location: Odisha, India


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

brnldist-1.0.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

brnldist-1.0.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file brnldist-1.0.0.tar.gz.

File metadata

  • Download URL: brnldist-1.0.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for brnldist-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2e230336d8f96176faca144a06ba9bf90d037cda9d3caa6b8f09ddb8c4b4599e
MD5 ca27953b5d00dbf980313997d35be2d4
BLAKE2b-256 2b32d8f24f8f3311188d4bb053cde33438673f2c2afbfb101f87d4b5f6cdd279

See more details on using hashes here.

File details

Details for the file brnldist-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: brnldist-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for brnldist-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 639be84d5ad739510cc5da972129bf09db2b2ca663dcb7ba6e9f5b0876502d3b
MD5 c9c4ad715063b04b353707c4dd83548d
BLAKE2b-256 1a272b444ad96364687322350eaeb6080db76492dd2e93235d911e6bf8b09f44

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