]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Improve docstring for random.binomialvariate (gh-131164)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Wed, 12 Mar 2025 18:25:31 +0000 (13:25 -0500)
committerGitHub <noreply@github.com>
Wed, 12 Mar 2025 18:25:31 +0000 (13:25 -0500)
Add probability distribution to the docstring

Lib/random.py

index 1abcae77c8be577cf699aee20e62efb49bc8394f..4d9a047b027974fc6318497f1b9c81ce3b2ea7b2 100644 (file)
@@ -792,12 +792,18 @@ class Random(_random.Random):
 
             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