Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,17 @@ def weibullvariate(self, alpha, beta):
u = 1.0 - self.random()
return alpha * (-_log(u)) ** (1.0/beta)

## -------------------- Binomial distribution --------------------

def binomialvariate(n, p):
""" Binomial distribution for the number of successes
in *n* Bernoulli trials each with a probability *p*
of success.

Returns an integer in the range: 0 <= X <= n
"""
return sum(self.random() < p for i in range(n))

## --------------- Operating System Random Source ------------------

class SystemRandom(Random):
Expand Down