Skip to content

Commit 488f706

Browse files
committed
Add probability distribution to the docstring
1 parent 5e73ece commit 488f706

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Lib/random.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,12 +792,18 @@ def binomialvariate(self, n=1, p=0.5):
792792
793793
sum(random() < p for i in range(n))
794794
795-
Returns an integer in the range: 0 <= X <= n
795+
Returns an integer in the range:
796+
797+
0 <= X <= n
798+
799+
The integer is chosen with the probability:
800+
801+
P(X == k) = math.comb(n, k) * p ** k * (1 - p) ** (n - k)
796802
797803
The mean (expected value) and variance of the random variable are:
798804
799805
E[X] = n * p
800-
Var[x] = n * p * (1 - p)
806+
Var[X] = n * p * (1 - p)
801807
802808
"""
803809
# Error check inputs and handle edge cases

0 commit comments

Comments
 (0)