https://github.com/python/cpython/commit/25f24b01e3b675c6afbb653f07034a3c9a6aee32
commit: 25f24b01e3b675c6afbb653f07034a3c9a6aee32
branch: main
author: Raymond Hettinger <[email protected]>
committer: rhettinger <[email protected]>
date: 2025-03-12T13:25:31-05:00
summary:
Improve docstring for random.binomialvariate (gh-131164)
Add probability distribution to the docstring
files:
M Lib/random.py
diff --git a/Lib/random.py b/Lib/random.py
index 1abcae77c8be57..4d9a047b027974 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -792,12 +792,18 @@ def binomialvariate(self, n=1, p=0.5):
sum(random() < p for i in range(n))
- Returns an integer in the range: 0 <= X <= n
+ Returns an integer in the range:
+
+ 0 <= X <= n
+
+ The integer is chosen with the probability:
+
+ P(X == k) = math.comb(n, k) * p ** k * (1 - p) ** (n - k)
The mean (expected value) and variance of the random variable are:
E[X] = n * p
- Var[x] = n * p * (1 - p)
+ Var[X] = n * p * (1 - p)
"""
# Error check inputs and handle edge cases
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]