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
-
Uses LCG to generate a sequence of pseudo-random integers:
$$ X_{n+1} = (a \cdot X_n + c) \mod m $$
-
Normalizes each LCG value to the interval [0, 1] by dividing by the modulus
m. -
Compares each normalized value with a probability threshold
p:- If the value <
p→ return1(success) - Else → return
0(failure)
- If the value <
-
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e230336d8f96176faca144a06ba9bf90d037cda9d3caa6b8f09ddb8c4b4599e
|
|
| MD5 |
ca27953b5d00dbf980313997d35be2d4
|
|
| BLAKE2b-256 |
2b32d8f24f8f3311188d4bb053cde33438673f2c2afbfb101f87d4b5f6cdd279
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
639be84d5ad739510cc5da972129bf09db2b2ca663dcb7ba6e9f5b0876502d3b
|
|
| MD5 |
c9c4ad715063b04b353707c4dd83548d
|
|
| BLAKE2b-256 |
1a272b444ad96364687322350eaeb6080db76492dd2e93235d911e6bf8b09f44
|